wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes how to invoke the first superclass constructer with out invoking the subclass constructer..? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to invoke the first superclass constructer with out invoking the subclass constructer..?" Watch "how to invoke the first superclass constructer with out invoking the subclass constructer..?" New topic
Author

how to invoke the first superclass constructer with out invoking the subclass constructer..?

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Dear All

The program discription :_




Kindly tell me the statement to invoke A default constructer from c default constructer with out using executing B default constructer


Creativity is nothing but Breaking Rules
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You can't. this() and super() can only be called from a constructor context. And you can't do super().super() or something like that. Only the super class is visible. If you just want an A object then just directly call the constructor.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Not Possible. You cant break the Constructor Chaining.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Wouter win the race!
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Thanks a lot....
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Let me "try" to explain why ....
ahem

C extends B and B extends A

So, if you want to create an Object of C, A has to be created *, or a better word would be .. Constructed.
Next, B will be constructed and then C.

Thus the constructors will be called in that order.
You can choose to call a specific Immediate parent constructor by using super keyword

However skipping B's constructor would mean that C will be created without B and thus will not work.

* Note that only one object is created not 3

My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Better to say that part of the C object which is unchanged from A is created, then that part unchanged from B, but not in A, then the parts only in C.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to invoke the first superclass constructer with out invoking the subclass constructer..?