What is meant by method overriding

Showing Answers 1 - 2 of 2 Answers

padma

  • Oct 10th, 2005
 

       Redefining  the functionality..

  Was this answer useful?  Yes

There is difference between overloading and overriding. In overriding you can add additional parameter to the function of the base class which does not affect the base class.The respective class(base or derived)will be called depending upon the no of parametres. Assume student as a base class and HostelStudent as a derived class class Student { void disp() { int roll; String name; System.out.println( "Roll:"+roll); System.out.println( "Name:"+name); }}class HostelStudent extends Student{ void disp() { super();//name,roll are derived //add a new attribute roomno int rno; System.out.println( "RoomNo:"+rno); } public static void main(String args[]) { HostelStudent h = new HostelStudent(); h.disp(1010,"abc", 12); Student s = new Student(); s.disp(1010,"abc"); }} The main theme is that we can reuse the base class method(using super keyword) and also make modifications in derived class which only affects that derived class

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions