What is the result?

Given:

1. public interface A { public void m1(); }
2.
3. class B implements A { }
4. class C implements A { public void m1() { } }
5. class D implements A { public void m1(int x) { } }
6. abstract class E implements A { }
7. abstract class F implements A { public void m1() { } }
8. abstract class G implements A { public void m1(int x) { } }

What is the result?

Given:

1. public interface A { public void m1(); }
2.
3. class B implements A { }
4. class C implements A { public void m1() { } }
5. class D implements A { public void m1(int x) { } }
6. abstract class E implements A { }
7. abstract class F implements A { public void m1() { } }
8. abstract class G implements A { public void m1(int x) { } }

What is the result?

A.
Compilation succeeds.

B.
Exactly one class does NOT compile.

C.
Exactly two classes do NOT compile.

D.
Exactly four classes do NOT compile.

E.
Exactly three classes do NOT compile.

Explanation:
Main.java:3: B is not abstract and does not override abstract method m1() in A
class B implements A { }
^
Main.java:5: D is not abstract and does not override abstract method m1() in A
class D implements A { public void m1(int x) { } }
^
2 errors



Leave a Reply 1

Your email address will not be published. Required fields are marked *