What is the difference between hiding & overriding ?

Questions by anilktomar

Showing Answers 1 - 6 of 6 Answers

g_chetanraj

  • Apr 3rd, 2006
 

overloading is related to one particular class.If we define two methods in the same class with same name,but different input parameters. Then it is called overloading.Overridig is related to super and sub class.He you define a method with same name , accepting same parameter as that of your super class. then the method in the sub class is said to override the method in the super class.

  Was this answer useful?  Yes

Anil Tomar

  • Apr 3rd, 2006
 

Sir u r telling the difference Between Overriding & overloading but m asking Difference b/W Hiding & overriding.

  Was this answer useful?  Yes

Dishu

  • Apr 5th, 2006
 

when you override a method, you still get the benefits of run-time polymorphism, and when you hide, you don't

  Was this answer useful?  Yes

Tindu

  • Apr 7th, 2006
 

Consider the following eg:
public class Animal {    public static void hide() {        System.out.format("The hide method in Animal.%n");    }    public void override() {        System.out.format("The override method in Animal.%n");    }}
public class Cat extends Animal {    public static void hide() {        System.out.format("The hide method in Cat.%n");    }    public void override() {        System.out.format("The override method in Cat.%n");    }    public static void main(String[] args) {        Cat myCat = new Cat();        Animal myAnimal = myCat;        Animal.hide();       //Better!        myAnimal.override();    }}
* In the Cat class we can say that the non-static method override() is overriden but 
we can't say that the static method hide() is overriden, instead its hidden !
* Only accessible, non-static method can be overriden.
* static method can be hidden.

  Was this answer useful?  Yes

Deepthik

  • Apr 26th, 2006
 

 

          Hiding is similar to the private variables which are hidded by the other classes even in the same package, i.e giving restricted access to the objects. But Overriding is using the same signature for different functionality in different classes.

Cheers,

DeepthiMahesh                                                                                                                   

  Was this answer useful?  Yes

SrinivaS

  • May 30th, 2006
 

Hi,

Variables can also be overridden, it?s known as shadowing or hiding. But, member variable references are resolved at compile-time. So at the runtime, if the class of the object referred by a parent class reference variable, is in fact a sub-class having a shadowing member .

 

ok bye..

keeps smiling and mailing

bora_srinivasarao@yahoo.co.in

note: if any want java faq's ,java materials,java e-books, just send a mail to me.

if any one having doubts regarding java ,just send a mail to m. if possible i will clarify.

 

  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