63 Whenever we create object for sub class JVM only provides memory for sub class not for super class

Code:

class A
{
int a = 111;
int b = 222;
}

class B extends A
{
int c = 333;
int d = 444;

B()
{
System.out.println(" Sub Class memory this: "+this.hashCode() );
System.out.println(" Sub Class memory super: "+super.hashCode() );
System.out.println(" \n Sub Class memory this: "+this.getClass().getName() );
System.out.println(" Sub Class memory super: "+super.getClass().getName() );
}

}


class Test
{
public static void main( String[] s )
{
B obj = new B();

System.out.println(obj.a);
System.out.println(obj.b);
System.out.println(obj.c);
System.out.println(obj.d);
}
}

Output:


Previous
Next Post »