Page 1 of 1

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

Posted: Fri Jan 08, 2021 1:37 am
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."

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

Posted: Fri Jan 08, 2021 3:40 am
by admin
Updated in 817 question bank.
thank you for your feedback!

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

Posted: Fri Jan 08, 2021 4:16 am
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

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

Posted: Fri Jan 08, 2021 4:54 am
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.

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

Posted: Fri Jan 08, 2021 5:07 am
by teodorj
Noted Thanks :)

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

Posted: Mon Feb 13, 2023 6:29 am
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.

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

Posted: Mon Feb 13, 2023 9:58 am
by admin
I did not understand what exactly are you getting at. Can you explain your point with an example?

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

Posted: Fri Feb 17, 2023 5:53 am
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";
    }
}

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

Posted: Fri Feb 17, 2023 8:16 am
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.

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

Posted: Tue Oct 10, 2023 7:57 am
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?

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

Posted: Tue Oct 10, 2023 9:07 am
by admin
What happened when you tried compiling it?

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

Posted: Wed Oct 11, 2023 8:20 am
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.

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

Posted: Thu Oct 12, 2023 11:07 am
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.

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

Posted: Fri Oct 13, 2023 4:09 pm
by AlienFS
Ah yes. I got it mixed up as an interface itself has default visibility "package".