| Author |
a bug with a constructor
|
alex lotel
Ranch Hand
Joined: Feb 01, 2008
Posts: 191
|
|
i dont know what the problem here?
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Originally posted by donaldth smithts: i dont know what the problem here? [/CODE]
If you tell us the symptoms we may be able to diagnose it.
|
Joanne
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
You are passing the value a to the 2nd constructor and giving it the title "a". Then you are giving "a" the value of b in the 1st constructor. Does that help?
|
 |
alex lotel
Ranch Hand
Joined: Feb 01, 2008
Posts: 191
|
|
it says "implicit super constructor A() is undefined.Must explicitly invoke another constructor" can you tell me whats the mistake in normal words?
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
If you don't include a call to any of the parent class constructors (using super) in your constructors, then the compiler implicitly includes a call to the parent classes no arg constructor. If the parent class doesn't have a no arg constructor then you get this error. The solution is to either add a no arg constructor to your A class or explicitly include a call to one of the A class constructors in your B class constructors. e.g.
|
 |
Roger Chung-Wee
Ranch Hand
Joined: Sep 29, 2002
Posts: 1683
|
|
Whenever a class is instantiated, then so are all the other classes up to and including Object. Let's look at the constructor of class B. This is the same as: So, either you have to create a no-argument constructor in class A or amend your code like this to invoke the constructor in class A:
|
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
|
 |
alex lotel
Ranch Hand
Joined: Feb 01, 2008
Posts: 191
|
|
|
thanks
|
 |
 |
|
|
subject: a bug with a constructor
|
|
|