1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anastaziya [24]
3 years ago
5

Consider the following class definitions. public class Computer { private String memory; public Computer) { memory = "RAM"; } pu

blic Computer (String m) { memory = m; } public String getMemory () { return memory; ) } public class Smartphone extends Computer private double screenWidth, screenHeight; public Smart Phone (double w, double h) super("flash"); screenWidth = w; screenHeight = h; } public double get ScreenWidth() { return screenWidth; } public double getScreenHeight() { } return screenHeight; } The following code segment appears in a class other than Computer or Smartphone. + Computer myPhone = new Smart Phone (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?A. An error occurs during compilation because a Smartphone object cannot be assigned to the Computer reference variable myPhone. B. An error occurs during compilation because the Smartphone class has no getMemory method. C. An error occurs during compilation because the getScreenWidth and getScreenHeight methods are not defined for the Computer object myPhone. D. An error occurs at runtime because the Smartphone class has no getMemory method. E. An error occurs at runtime because the getScreenWidth and getScreenHeight methods are not defined for the Computer object myPhone.
Computers and Technology
1 answer:
chubhunter [2.5K]3 years ago
8 0

Answer:

C.

Explanation:

The code provided in the question has many syntax errors. I have pasted a fixed version of the code below that fixes all the syntax errors but leaves the code as is. Using this code you can see that the error that is preventing the code from running properly is that

C. An error occurs during compilation because the getScreenWidth and getScreenHeight methods are not defined for the Computer object myPhone.

As you can see from the attached photo below, the code is failing to compile because the methods themselves are not able to be accessed by the myPhone object. This is happening during the compilation and thus causing the compilation to fail.

class Computer {

   private String memory;

   public Computer() {

       memory = "RAM";

   }

   public Computer(String m) {

       memory = m;

   }

   public String getMemory() {

       return memory;

   }

}

   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;

       }

   }

   public class Main{

       //The following code segment appears in a class other than Computer or Smartphone

       

       public static void main(String[] args) {

           Computer myPhone = new Smartphone(2.55, 4.53);

           System.out.println("Device has memory: " + myPhone.getMemory() + ", screen area: " + (myPhone.getScreenWidth()*myPhone.getScreenHeight()) +" square inches.");

       }

   }

You might be interested in
How do i delete a question ?
seraphim [82]

i think we can't do that

7 0
3 years ago
If your vehicle has fuel injection and the engine is cold,
olga nikolaevna [1]
D. Press the accelerator to the floor once and release it.
6 0
3 years ago
Describe the different non-printing characters,​
irakobra [83]

Answer:

or formatting marks are characters for content designing in word processors, which aren't displayed at printing. It is also possible to customize their display on the monitor. The most common non-printable characters in word processors are pilcrow, space, non-breaking space, tab character etc.

Explanation:

5 0
3 years ago
Which of the following Python methods in scipy.stats submodule returns the P-value for performing a hypothesis test for the sign
ipn [44]

Answer:

Option B is the correct answer for the following question.

Explanation:

The following option is true because the pearsonr from scipy module is the method of the Python Programming Language in the submodule i.e., "scipy.stats" which print or return P-value for operating the hypothesis test for the value of correlation coefficient. So, that's why the following option is correct.

7 0
3 years ago
In the U.S. highway numbering system, north-south routes have
aniked [119]

Answer:

B. "1"

Explanation:

Major north–south routes have numbers ending in "1" while major east–west routes have numbers ending in "0".

Hope this helps!

5 0
3 years ago
Read 2 more answers
Other questions:
  • Which connector is most commonly used to connect printers to desktop pc systems?
    10·1 answer
  • What are three reasons teens might start drinking alcohol??
    7·2 answers
  • What coding language should i begin with if i'm looking to get into AI ?
    11·1 answer
  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    7·1 answer
  • How do you answer a question on here
    5·2 answers
  • Why might a neurosurgeon receive a higher wage than a nail technician ?
    12·2 answers
  • Write a method __repr__(self) that returns a string representing an AIPlayer object. This method will override/replace the __rep
    13·1 answer
  • The volumes of data collected by contemporary organizations are so huge that they are beyond the ability of typical DBMS to capt
    13·1 answer
  • Create a program that a professor can use to display a grade for any number of students. Each student's grade is based on four t
    10·1 answer
  • You are investigating a problem between two wireless bridges and you find that signal strength is lower than expected. Which of
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!