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
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();
}
}
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.
This section is not available anymore. Please use the main Exam Page.1z0-809 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
jduarte
Highly Voted 4 years, 3 months agoMPignaProTech
Most Recent 6 months, 1 week agoshivkumarx
1 year, 2 months agoasdfjhfgjuaDCV
1 year, 2 months agoasdfjhfgjuaDCV
1 year, 2 months agosteefaand
1 year, 3 months agor1muka5
2 years, 3 months agodexdinh91
2 years, 8 months agokarta
2 years, 9 months agoTarik2190
4 years, 1 month agoTarik2190
4 years, 1 month agoJME_CHG
4 years, 1 month agovarconite
4 years, 6 months ago