When subclasses are created, they may have their own methods in addition to the inherited methods from superclass. It is possible for methods in subclass to have the same name and type as those of the superclass. In that case the method of subclass is override the method of superclass. override the method in the super class..
For example
class abc{
void msg(){
System.out.println("Now in class abc");
}
}
class xyz extends abc{
void msg(){
System.out.println("Now in class xyz");
}
}
class OverRide{
public static void main(String args[]){
xyz obj1= new xyz();
abc obj2= new abc();
obj1.msg();
obj2.msg();
}
}
This program will output Now in class xyz Now in class abc So here the msg() method of class xyz override the method of its superclass abc.....
1 comments:
Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.
DevOps Training in Bangalore
DevOps Training in Bangalore
DevOps Training in Bangalore
DevOps Training in Marathahalli
DevOps Training in Pune
DevOps Online Training-gangboard
Post a Comment