Function Overriding:-
We will create same name method from base class to derived class only functionality will be different.
Overriding is used to extend the particular functionality of class ,without interfere to actual class.
For example ExamSystem ,Old system is based on Number and now based on Grade
class Exam
{
public void examInfo()
{
System.out.println("Main Exam");
}
public void examPattern()
{
System.out.println("Number System");
}
}
class Examnew extends Exam
{
public void examPattern()
{
System.out.println("Grade System");
}
public static void main(String[] args) {
Examnew obj = new Examnew();
obj.examInfo();
obj.examPattern();
Exam obj1 = new Examnew();
obj1.examPattern();
Exam obj2 = new Exam();
obj2.examPattern();
}
}
We will create same name method from base class to derived class only functionality will be different.
Overriding is used to extend the particular functionality of class ,without interfere to actual class.
For example ExamSystem ,Old system is based on Number and now based on Grade
class Exam
{
public void examInfo()
{
System.out.println("Main Exam");
}
public void examPattern()
{
System.out.println("Number System");
}
}
class Examnew extends Exam
{
public void examPattern()
{
System.out.println("Grade System");
}
public static void main(String[] args) {
Examnew obj = new Examnew();
obj.examInfo();
obj.examPattern();
Exam obj1 = new Examnew();
obj1.examPattern();
Exam obj2 = new Exam();
obj2.examPattern();
}
}
Post a Comment
POST Answer of Questions and ASK to Doubt