Java OCA OCP Practice Question 120

Question

Given:

interface Device { 
  void doStuff(); 
} 
abstract class Electronic { 
  void getPower() { System.out.print("plug in "); } 
} 
public class Computer extends Electronic implements Device { 
  void doStuff() { System.out.print("show book "); } 
  public static void main(String[] args) { 
    new Computer().getPower(); 
    new Computer().doStuff(); 
  } //w  w  w.j a v  a  2s  .  c  o m
} 

Which are true?

Choose all that apply.

  • A. The class Computer will NOT compile
  • B. The interface Device will NOT compile
  • C. The output will be plug in show book
  • D. The abstract class Electronic will NOT compile
  • E. The class Computer CANNOT both extend and implement


A is correct.

Note

By default, an interface's methods are public so the Computer.doStuff method must be public, too.

The rest of the code is valid.

B, C, D, and E are incorrect.




PreviousNext

Related