59 Program on Single Level Inheritance in Java

Code:

// Program on single level inheritance

class A extends Object
{

}

class Test
{
public static void main( String[] args )
{
A obj = new A();
System.out.println(" Memory: "+obj.hashCode() );

// There is no hashCode() method in Test and A class but it is not
// giving any error because it is extending Object class and the method is available in Object Class

Test t = new Test();
System.out.println(" Memory: "+t.hashCode() );

}
}


Output:


Previous
Next Post »