Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/how-to-implement-an-interface-in-java
Question 195 / 297:  To resolve the compilation error(s) in the following code, what can be done independently :
Choose 2
interface Movable {

public abstract void m1(); // line 1

void m2(); // line 2

public void m3(); // line 3

abstract void m4(); // line 4

}

class Chair implements Movable { // line 5

public void m1() { } // line 6

void m2() { } // line 7

}

<< First < Previous Next > Last >>
Explanation:

Methods declared in an interface are by default "public abstract", even if you didn't explicitly write the words "public abstract" in front of each method.

Chair is a "class" implementing Movable, so Chair must implement all methods of Movable(Answer 4). Pay attention to the fact that when implementing m2(),m3() and m4() you cannot reduce their access visibility (must mark them public)

Another solution to resolve the errors, is to convert Chair to an "abstract class", which can choose what to implement from its super (Movable).

Answer 2, suggests marking Chair abstract and choosing not to implement m3() and m4() and implementing only m2(). But implementing m2() requires marking it public for the fact mentioned at the beginning.

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Madison Christian
Start Flashcards
Yasser Ibrahim
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>