• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

a bug with a constructor

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont know what the problem here?

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80950
522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
I've never won anything before. Not even a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic