Page 1 of 1

question on enthuware.ocpjp.v8.2.1251

Posted: Mon Jun 12, 2017 1:47 pm
by Asymmetriccat
Hello,
I have difficulty to understand the question as in the title, also as below. Can anybody help? In the explanation, it mentioned: "It is given that A implements a method. Since Java 8 allows interfaces to contain method implementation as well, that means it can be a class or an interface. Further, it is given that A declares a method but does not implement it, that means, if it is a class, it must be an abstract class."

But I have not see that any interface could implements any method in another interface so far. I tried writing such kind code in Eclipse but got compiling error.

public interface InterfaceImplement extends A{
int add(int a, int b){}; //compiling error in this line
}

interface A{
int add(int a, int b);
}

Can anybody provide a solid example for better understanding? Thanks a lot in advance!

Original question as below:
Given:

Type A is a template for other types in the application.
Type A implements method process().
Type A declares but does not implement method prepare().

Which of the following statements are correct?
a. A must be an interface.
b. A must be an abstract class.
c. A may be an abstract class or an interface.
d. A must implement an interface.

c is the answer from Enthuware.

Re: question on enthuware.ocpjp.v8.2.1251

Posted: Mon Jun 12, 2017 8:54 pm
by admin
Implementing a method means having code for the method. It does not imply having an implements clause. For example, the following interface can be said to implement the method add:

public interface Interface{
default int add(int a, int b){ };
}

On the other hand, "implementing an interface" means having an implements clause.

Re: question on enthuware.ocpjp.v8.2.1251

Posted: Tue Jun 13, 2017 3:44 pm
by Asymmetriccat
Sounds making sense. Thanks a lot!!!

admin wrote:Implementing a method means having code for the method. It does not imply having an implements clause. For example, the following interface can be said to implement the method add:

public interface Interface{
default int add(int a, int b){ };
}

On the other hand, "implementing an interface" means having an implements clause.