There is nothing like trying, either you do it or you don't.
SCJP 1.5
Mahesh Bamane wrote:Let's say I've Class A, Class B and Class C.
Now C->extends B -> Extends A
Now I write C c = new C();
Now how many objects will be created over here?
There is nothing like trying, either you do it or you don't.
SCJP 1.5
Mahesh Bamane wrote:Here a call to super constructor will also go right?
Mahesh Bamane wrote:
Whats the use of calling super?
Mahesh Bamane wrote:
Just wanted to understand what happens underneath? Why there is need of calling super while creating an object?
Campbell Ritchie wrote:Have a look at the Java Language Specification, which explains the order in which objects are created. You see you must call a superclass’ constructor. The super(); or super(x, y, z); calls tell the compiler which superclass’ constructor to call.
Mahesh Bamane wrote:Now how many objects will be created over here?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There is nothing like trying, either you do it or you don't.
SCJP 1.5
There is nothing like trying, either you do it or you don't.
SCJP 1.5
Mahesh Bamane wrote:Thanks for your reply.
If only one object is created then why super is called? (might be a stupid doubt)
I mean doesn't super() creates super class object? What is the benefit of calling super()?
If I put S.O.P in class A, B anc C's countructor and create on C's object i.e. C c = new C(), all three are printed. Doesn't that mean 3 objects are created?
Mahesh Bamane wrote:
If only one object is created then why super is called?
Whenever a new class instance is created, memory space is allocated for it with room for all the instance variables declared in the class type and all the instance variables declared in each superclass of the class type, including all the instance variables that may be hidden
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |