Method Overriding happens when the method (function) having the same signature as that of the base class overrides the original method. This makes it possible for the method of the derived class to be used and not the base class.
Language : Java
Related : Method Overloading in Java
[sourcecode language='java']
//Method Overriding
class marks
{
private int total;
private float avg;
marks()
{
total=511;
avg=(total/7);
}
void show() //Show of marks
{
System.out.println(“Average : “+avg);
}
}
class Student extends marks
{
String name;
int roll;
Student()
{
name=”ABC”;
roll=123456;
}
void show() //Show of Student
{
System.out.println(“Name “+name+”\n”+”Roll : “+roll);
}
}
class mainMethod
{
public static void main(String args[])
{
Student std=new Student();
std.show(); //Show of marks is overriden by show of Student
}
}
[/sourcecode]







{ 4 comments… read them below or add one }
Hi Vaibhav,
Thaks for the script, hmm may i expect php in future ?
Your site is with very usefull information, keep rocking!
@Str
Thanks for the appreciation, Yes, I would include PHP scripts soon. Programming Kid is relatively new and I am posting Source codes every week.
Stay connected!
Hi Vaibhav,
Thaks for the script, hmm may i expect php in future ?
Your site is with very usefull information, keep rocking!
@Str
Thanks for the appreciation, Yes, I would include PHP scripts soon. Programming Kid is relatively new and I am posting Source codes every week.
Stay connected!