This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes a  bug with a constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "a  bug with a constructor" Watch "a  bug with a constructor" New topic
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: 3606
    
  15
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: 39089
    
  23
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: 3606
    
  15
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
 
GeeCON Prague 2014
 
subject: a bug with a constructor