Method Overloading Vs Method Overriding

Following concepts demonstrate different types of polymorphism in java;

1) Method Overloading
2) Method Overriding


1)Method Overloading:
In Java, it is possible to define two or more methods of same name in a class, provided that there argument list or parameters are different. This concept is known as Method Overloading.


Rules for Method Overloading
  1. Overloading can take place in the same class or in its sub-class.
  2. Overloaded methods must have a different argument list.
  3. The parameters may differ in their type or number, or in both.
  4. They may have the same or different return types.
  5. It is also known as compile time polymorphism.
2) Method Overriding
Child class has the same method as of base class. In such cases child class overrides the parent class method without even touching the source code of the base class. This feature is known as method overriding.
Rules for Method Overriding:
  1. Applies only to inherited methods
  2. object type determines which overridden method will be used at runtime.
  3. Overriding method can have different return type.
  4. Abstract methods must be overridden
  5. Static and final methods cannot be overridden.
  6. It is also known as Runtime polymorphism.

Comments

Popular posts from this blog

Operating System | Best Definition of Opetating System

Umbrella activities in Software Engineering