Given the content of Operator.java, EngineOperator.java, and Engine.java files:
and the code fragment:What is the result?
Given the content of Operator.java, EngineOperator.java, and Engine.java files:
and the code fragment:What is the result?
answer is C becouse method is protected abstract void turnOn(); protected abstract void turnOFF();
answer is C
Answer is C: There are 2 ways to print output as ON/OFF: 1) methods turnON() and turnOFF() need to be declared as abstract. or 2) methods turnON() and turnOFF() need to be declared as protected void turnON() {some code here...}. Only then, EngineOperator class will be able to override these methods.
C but if corrected, then there are 2 possibilities: 1. if all classes in same package, then D. 2. if not in same package, then A.
If we do not make changes to turnON() and turnOFF() methods, then Operator class will not compile. class abstract class Operator { protected void turnON(); protected void turnOFF(); } class EngineOperator extends Operator { public final void turnON() { System.out.println("ON"); } public final void turnOFF() { System.out.println("OFF"); } } class Engine { Operator m = new EngineOperator(); public void operate() { m.turnON(); m.turnOFF(); } } public class Test { public static void main(String[] args) { Engine carEngine = new Engine(); carEngine.operate(); } }
Abstract classes do not implicitly add abstract modifier Even if abstract modifier was added, the Engine class compiles fine and the code prints ON OFF
Answer is D.
C is corrcet sorry for above
C is correct since methods are not declared abstract but dont have body.
Correct answer - C
methods do not have body in class Operator
answer is C the Operator class turnON()& turnOFF() method need the body or change to abstract