,
Share with your friends 

java inheretence calling of constructor and memory allocation to objects

6 ratings Views 94 
Author: Bhanu Kumar Yadav (Bhanu Kumar Yadav Shine in IT sector)  View Profile |  View other solutions by this author

Question / Problem


How constructors are called in multi - level inhertence,when object of child class is created?

Solution

First base class constructor is called and then the Child class.This concept helps to understand the concept of memory allocation to objects im System.

class A
{
A()
    System.out.println("Hello A \n");
}
}
class B extends A
{
B()
    System.out.println("Hello B \n");
}
}

class C extends B
{
C()
    System.out.println("Hello C \n");
}
}

class my
{
public Static void main(String a[])
{
   C c=new C();
}
}

output :
 Hello A
 Hello B
 Hello C


Applies to

Core Java

Rank It

Login to rank it

Report


Advertisement