Search This Blog

15 June, 2011

Simple Java program related to inheritance - part 2

In case of inheritance a base class pointer is capable of storing address of an object created from its derived class but through that pointer the methods of the derived class can't be accessed unless they are part of base class. And vice-versa is not possible.


class aaa 
{
}
class bbb extends aaa
{
}
class sss
{
public static void main(String gg[])
{
aaa a;
a=new bbb(); // Correct
bbb b;
b=new aaa();  // Incorrect
}
}


-----------------------------------------------------------------

No comments:

Post a Comment

Meetme@