Question: Consider the following class definitions. public class Computer { private String memory; public Computer ( ) { memory = RAM; } public Computer ( String

Consider the following class definitions.
public class Computer
{
private String memory;
public Computer()
{
memory = "RAM";
}
public Computer(String m)
{
memory = m;
}
public String getMemory()
{
return memory;
}
}
public class Smartphone extends Computer
{
private double screenWidth, screenHeight;
public SmartPhone(double w, double h)
{
super("flash");
screenWidth = w;
screenHeight = h;
}
public double getScreenWidth()
{
return screenWidth;
}
public double getScreenHeight()
{
return screenHeight;
}
}
The following code segment appears in a class other than Computer or Smartphone.
Computer myPhone = new SmartPhone(2.55,4.53);
System.out.println("Device has memory: "+ myPhone.getMemory()+
", screen area: "+ myPhone.getScreenWidth()*
myPhone.getScreenHeight()+" square inches.");
The code segment is intended to produce the following output.
Device has memory: flash, screen area: 11.5515 square inches.
Which of the following best explains why the code segment does not work as intended?
Responses
An error occurs during compilation because a Smartphone object cannot be assigned to the Computer reference variable myPhone.
An error occurs during compilation because a Smartphone object cannot be assigned to the Computer reference variable myPhone .
An error occurs during compilation because the Smartphone class has no getMemory method.
An error occurs during compilation because the Smartphone class has no getMemory method.
An error occurs during compilation because the getScreenWidth and getScreenHeight methods are not defined for the Computer object myPhone.
An error occurs during compilation because the getScreenWidth and getScreenHeight methods are not defined for the Computer object myPhone .
An error occurs at runtime because the Smartphone class has no getMemory method.
An error occurs at runtime because the Smartphone class has no getMemory method.
An error occurs at runtime because the getScreenWidth and getScreenHeight methods are not defined for the Computer object myPhone.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!