Originally posted by Mrunal Bandodkar:
hi all,
During inheritence,say
class a
class b extends a
suppose if we create objects a A=new b();
A.print();
then should the print method occur in both the classes or if it is present in one that's ok.
Is there any rule or anything like that
either class can have the method print();
or if both have it then class B override class A's print();
there is one rule though, with:
A=new b();
A.print();
if class A doesn't have the method print() there will be compiler error. With that code, compiler see that the reference A is class A and it doesn't have method print() even thought at runtime the method that will be called is the actually Object.