java inheretence calling of constructor and memory allocation to objects
|
|
|
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 |
|