Java OCA OCP Practice Question 2315

Question

Examine the following code and select the answer options that are correct individually.

class Shape { 
    void start() throws Exception { System.out.println("start machine"); } 
} 
class Laptop { 
    void start() { System.out.println("Start Laptop"); } 
    void start(int ms) { System.out.println("Start Laptop:"+ms); } 
} 
  • a Class Laptop overloads method start().
  • b Class Laptop overrides method start().
  • c Class Shape overrides method start().
  • d Class Shape won't compile.
  • e Class Laptop won't compile.


a

Note

Class Laptop correctly overloads the method start() by defining a different parameter list.

Options (b) and (c) are incorrect because classes Laptop and Shape are unrelated.

A derived class can override its base class method.

Method start() qualifies as a valid overridden method in class Laptop, if Laptop extends class Shape.

It's acceptable for an overriding method to not throw any checked exception, even if the base class method is throwing a checked exception.

Options (d) and (e) are incorrect because both classes will compile successfully.




PreviousNext

Related