• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Implicit super constructor is undefined

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I did some searching on this problem and nothing I tried fixed it so here goes:

I am working with inheritance for the first time. Trying to write a program with a parent class that has a child class that is also a parent class to a third class. Parent is called Player, child: ComputerPlayer, and child of that: NaiveComputerPlayer. I am getting an error in my ComputerPlayer class saying that the super constructor is undefined for the Player() class. Here is my code for the parent class:
and here is the code for the child class, ComputerPlayer:

As you can see, I tried to include a default constructor in Player with no parameters, which the sites I found recommended for my problem, but the error persists in the ComputerPlayer class. Can anyone tell me what I am missing? Just in point of fact, I am only using ComputerPlayer as a platform to extend Player to the types of computer player bots I am writing, which is why there is nothing but a constructor there, which, again, is what I thought I needed to use inheritance for the respective child classes. As always, I really appreciate any help you might offer.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you certain the code giving the error is the same as the code you've posted? Because I've just tried that, and it compiles fine.

(As things stand the super() call in your subclass is unnecessary because the compiler will insert it for you. In fact, you could delete both constructors at the moment and it would have no effect.)
 
james falk
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sure it's the same code. I am also getting an error in my main method that says I cannot instantiate the type Player, does that help? Here's a code snippet from the main method:



I get an error on that third and fourth line about instantiation
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you recompiled Player since adding the empty constructor? Do you have another class named Player in your classpath which both the main method and the subclass may be using instead of the one you are changing?
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

james falk wrote:I'm sure it's the same code. I am also getting an error in my main method that says I cannot instantiate the type Player, does that help? Here's a code snippet from the main method:



I get an error on that third and fourth line about instantiation



You can't instantiate Player directly because it is abstract, you can only instantiate a concrete sub-class of Player. So this error is unrelated to the constructor issue you are having.
 
james falk
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
turns out the problem was with the compiler. i rebooted it and no error is visible. Thanks for helping me clear up the instantiation problem, and thanks for taking a sec to help me try and figure out the constructor issue.
 
reply
    Bookmark Topic Watch Topic
  • New Topic