Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Medium
Question 26
Consider the code:
- interface Interf
- {
- void m1();
- public void m2();
- }
- class Test implements Interf
- {
- void m1(){}
- }
Which changes are required to perform independently to compile this code?
-
A
Just declare Test class as abstract.
-
B
Declare Test class as abstract and declare m1() method as public in Test.
-
C
Just provide implementation for m2() inside Test class.
-
D
Provide implementation for m2() inside Test class and declare m1() method as public in Test.
Reveal correct answers
Correct answers: B, D
Explanation
If a class implements an interface, then compulsory we should provide implementation for every abstract method, otherwise we have to declare class as abstract. Every interface method is public and hence at the time of implementation we should declare as public only.Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
