About Question enthuware.ocpjp.ii.v11.2.3510 :

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

Moderator: admin

Post Reply
teodorj
Posts: 33
Joined: Tue Jun 19, 2018 10:27 am
Contact:

About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by teodorj »

Given

Code: Select all

interface Book{
	public default String getId(){
		return "ISBN123456";
	}
}
interface Encyclopedia extends Book{
	//INSERT CODE HERE
}
One of the explanation states that:
You cannot override a static method with a non-static method. You can, however, redeclare a static method of a super interface as a default method in the sub interface.
I think the correct phrase would be "You cannot override a default method with a static method."

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

Updated in 817 question bank.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

teodorj
Posts: 33
Joined: Tue Jun 19, 2018 10:27 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by teodorj »

Hello enthuware,
I'm not able to update my question bank to latest version.
Both from Study view > Question bank and Tools > Check for question bank update
I have the latest ets viewer
Image

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

If multiple minor corrections reported during a small time frame, they are all applied together and then the version number is updated. This is done to ensure that users are not annoyed by too many update notifications in a short span.

If a critical error is fixed (such as a wrong answer to a question), we apply the fix, update the version number and release the new question bank file immediately.

So, in this case, the fix has been applied but the version number will be updated soon.
If you like our products and services, please help us by posting your review here.

teodorj
Posts: 33
Joined: Tue Jun 19, 2018 10:27 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by teodorj »

Noted Thanks :)

aPerson
Posts: 17
Joined: Fri Aug 12, 2022 10:19 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by aPerson »

Hi, a couple of the answers talk about redeclaring default methods. Isn't redeclaring (and hiding the original method) only for static methods? I tested different scenarios with the @Override-annotation and it seems to be in agreement with this.

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

I did not understand what exactly are you getting at. Can you explain your point with an example?
If you like our products and services, please help us by posting your review here.

aPerson
Posts: 17
Joined: Fri Aug 12, 2022 10:19 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by aPerson »

Well, it's a general question actually; can a default method in an interface be redecleared in an extending interface? I thought it can only be overridden.
The following code is one of the correct answers and it is referred to as a redeclaration. Isn't it an override?

Code: Select all

interface Book {
    public default String getId() {
        return "ISBN123456";
    }
}

interface Encyclopedia extends Book {

    default String getId() {
        return "AIN8888";
    }
}

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

Well, redeclaration is a non technical term. Technically meaningful terms would be overriding and hiding. Redeclaration just implies having the same method being present in a sub type. Whether that constitutes a valid override or a valid hiding depends on the situation.
From that perspective, I think yes, you can redeclare a default method of an interface in the sub-interface.
If you like our products and services, please help us by posting your review here.

AlienFS
Posts: 7
Joined: Tue Sep 05, 2023 4:07 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by AlienFS »

The question starts with:

Code: Select all

interface Book {
  public default String getId() {
    return "ISBN123456";
  }
}
interface Encyclopedia extends Book {
  //INSERT CODE HERE
}
your "good" answer:

Code: Select all

default String getId(){
  return "AIN8888";
};
An interface can redeclare a default method and provide a different implementation.
The visibility in the original class Book is public. You cannot reduce the visibility in a subclass, right? So your answer is not correct?

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

What happened when you tried compiling it?
If you like our products and services, please help us by posting your review here.

AlienFS
Posts: 7
Joined: Tue Sep 05, 2023 4:07 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by AlienFS »

Well it compiles. So, obviously, you are in the right. I didn't expect a default method to be allowed to change the visibility.

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

No, the reason it compiles is because all methods defined in an interface are public by default, unless they are explicitly defined as private. So, the default method in the given problem statement didn't change visibility. It is public even though not defined as public implicitly.
If you like our products and services, please help us by posting your review here.

AlienFS
Posts: 7
Joined: Tue Sep 05, 2023 4:07 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by AlienFS »

Ah yes. I got it mixed up as an interface itself has default visibility "package".

Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests