Search This Blog

16 June, 2011

Simple Java program related to inheritance - part 4

class aaa
{
public void sam()
{

System.out.println("hello");
}
public void tom()
{


}
}
class bbb extends aaa
{
public void tom()
{
System.out.println("good");
}
}
class psp
{
public static void main(String gg[])
{
aaa a;
a=new aaa();
a.tom();                 // tom will run of aaa class


aaa p;
p=new bbb();
p.tom();              // tom will run of bbb class.
}
}


Note:- But if this code is of C++ then (p.tom();) line runs tom of
           aaa class because in c++, the object of aaa can't store the 
           address of bbb class. 
----------------------------------------------------------------------------------

No comments:

Post a Comment

Meetme@