| Author |
calling grand parent's constructor
|
George Nan
Greenhorn
Joined: Mar 09, 2006
Posts: 3
|
|
How do you call parent's parent constructor? For example, Class B extends C, Class A extends B, in class A's constructor public A() { // how do you call C's constructor here? }
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
You can't.
|
 |
Zenikko Sugiarto
Ranch Hand
Joined: Jan 09, 2005
Posts: 58
|
|
Logically, A would call super() to call B's constructor, and B would call super() to call C's constructor. If you want to call A's constructor like that, then there should be a good reason to do that. Personally to me it sounded a bit weird,maybe if you outline your problem here, ppl can contribue their approaches in designing the 3 class... wrt to how to do that, Perhaps what you want is, declare a protected init() method in C that does some sort of initialization. In C's constructor, don't do anything but call this method. That way, init() carries out whatever C's constructor may carry out. And then. A can call init() - this approach is a bit lame and can only work if both B/A doesnt override init(). And a good design shouldnt rely things like that. [ April 04, 2006: Message edited by: Zenikko Sugiarto ]
|
 |
 |
|
|
subject: calling grand parent's constructor
|
|
|