Say I have a class Player, it has a method getRounds that takes some parameters
now say I have two subclasses of Player called Human and Computer, they both have methods getRounds that don't take any parameters
now I have a game class, in which I have two instances of players, in the constructor I cast both of the players, one to Computer and one to Human
in the game class, I have a method play, where I call player1.getRounds() and player2.getRounds(). the compiler is telling me that the playRounds() is not found in class Player...
I'm confused because I cast the Players already... so shouldn't it be calling the getRounds in Human and computer?
so I got the answer thanks to a helpful member on the board saying that i should cast the player as i call the getRounds, like ((Human)player1).getRounds.... it compiles, but now i get an exception java classcastexception exception... any ideas how to fix this?
now say I have two subclasses of Player called Human and Computer, they both have methods getRounds that don't take any parameters
now I have a game class, in which I have two instances of players, in the constructor I cast both of the players, one to Computer and one to Human
in the game class, I have a method play, where I call player1.getRounds() and player2.getRounds(). the compiler is telling me that the playRounds() is not found in class Player...
I'm confused because I cast the Players already... so shouldn't it be calling the getRounds in Human and computer?
so I got the answer thanks to a helpful member on the board saying that i should cast the player as i call the getRounds, like ((Human)player1).getRounds.... it compiles, but now i get an exception java classcastexception exception... any ideas how to fix this?