question on enthuware.ocpjp.v8.2.1251

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Asymmetriccat
Posts: 3
Joined: Mon Jun 12, 2017 1:13 pm
Contact:

question on enthuware.ocpjp.v8.2.1251

Post 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.

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: question on enthuware.ocpjp.v8.2.1251

Post 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.
If you like our products and services, please help us by posting your review here.

Asymmetriccat
Posts: 3
Joined: Mon Jun 12, 2017 1:13 pm
Contact:

Re: question on enthuware.ocpjp.v8.2.1251

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests