• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a bug with a constructor

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know what the problem here?

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48378
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic