• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Abstract class/methods (cannot find symbol)  RSS feed

 
hive mind
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having a little trouble with this program and using the abstract class. This is part of a dice game that is pretty much finished except for errors I am getting here. Here is the errors and the classes:

Here are the two errors I get, all of the java/class files are in the same folder.







I've looked for quite awhile looking for solutions and learning more about abstract classes but I can't seem to get it fixed. Any advice would be appreciated. Thanks!
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing about Java error messages that it is surprisingly hard to learn -- they're much more informative and accurate than in most other languages, at least the 8 or 10 I've dealt with.

The error message says you cannot override BeAPig because you are assigning a "weaker" access privileges. Well, the abstract class has it as public, and the method in the subclass has it declared without any access keywords, which means it is package protected. It cannot be package protected in the subclass and public in the superclass. You either have to make it package protected in the super, or public in the sub.

rc
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you really using class Human extends Player? Surely it is the other way round: class Player extends Human?
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And surely you want your fields to be boolean type, not Boolean.
 
Nico Van Brandt
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BeAPig?
Maybe you should consider extending from Animal
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nico Van Belle wrote: . . . extending from Animal
public class Human extends Animal?

Scientifically accurate, at least
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!