Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 ComputerString m memory m; public String getMemory return memory; public class Smartphone extends Computer private double screenWidth, screenHeight; public SmartPhonedouble w double h superflash; 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; System.out.printlnDevice 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: 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.
Consider the following class definitions.
public class Computer
private String memory;
public Computer
memory "RAM";
public ComputerString m
memory m;
public String getMemory
return memory;
public class Smartphone extends Computer
private double screenWidth, screenHeight;
public SmartPhonedouble w double h
superflash;
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;
System.out.printlnDevice 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: 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started