Question: Consider the following complete declarations. public abstract class Player public class ComputerPlayer extends Player { { private int myCount; public ComputerPlayer() { super(); } public

Consider the following complete declarations.

public abstract class Player public class ComputerPlayer extends Player
{ {
private int myCount; public ComputerPlayer()
{ super(); }
public Player() }
{ myCount = 0; }

public int count() public class SmartPlayer extends ComputerPlayer
{ return myCount; } {
public int play()
public void incCount(int amt) {
incCount(2);
{ myCount += amt; } return count();
}
public abstract int play(); }
}

public class Controller
{
public void doIt()
{
Player p = new SmartPlayer();
p.play();
}
}

You compile and run these classes with a driver class that correctly calls the Controller doIt method. Which of the following best describes the outcome?

The code does not compile because an abstract class cannot have an instance variable.

*ANSWER CHOICES*

A.) The code does not compile because an abstract class cannot have an instance variable.
B.) The code does not compile because an abstract class cannot implement a method.
C.) The code does not compile because a subclass cannot access an instance variable in its superclass, either directly or indirectly.
D.) The code does not compile because the class ComputerPlayer does not implement the method play and is not declared abstract.
E.) The code does not compile because the class SmartPlayer does not define a default (no parameter) constructor.

Step by Step Solution

3.48 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The correct answer is D The code does not compile because the class ComputerPlayer does not implemen... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!