Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions