Override methods V/S Overloading methods
Override methods is dynamic polymorphism. Overloading methods is static polymorphism.
Name of methods and parameter of methods are same in override.
Name of methods are same but parameter of methods are not same in overloading method.
“Override method possible only in inheritance class, because we can’t create same methods in same class.”
In this override method process sub class’s method overrides super class’s method. So super class method does not work on output screen.
System.out.println(“Welcome in A”);
class B extends A
void method() // NAme == method and Parameter () == same
System.out.println(“Welcome in B”);
public static void main(String args)
B obj = new B();
obj.method(); // override B class method to A Class method
Welcome in B
In this program, Super class A has method() function and Sub class B has same method() function and both class in inheritance. So when will call method() function that time sub class B’s method() function will override super class A’s method() function.
Video available on YouTube.
Share and Enjoy
272total visits,1visits today