Q. Explain method over ridding in java. Give example.
Ans. Method over ridding: In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its subclass then the method in the subclass in said to over ride the method in the super class. When an over ridden method is called from with a subclass it will always refer to the version of tat method defined the subclass. The version of the technique defined by the super class will be unseen. When show () is invoked on the object of type B, the version of show () defined in B is utilized. This is the version of show () inside B over riddles the version declared in A. If you want to access the super class version of an over ridden method function, you can do so by using super class. For example, in the version of B, the super class version is show () is invoked within the subclass version. This permits all instance variables to be exhibited.
Class B extends A
{ int K;
B { int a, int b, int c)
{ super (a, b)
K = c;
}
}
Method over ridding occurs only when the names and the types signature of the two methods are identical. If they are not then the two methods are simply over loaded.