There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Niranjan Welankiwar wrote:If interface does not extends Object class then can please someone explain me the below code :
In above case, "a" interface is the new interface declared. Yet, no class is implementing it. Then how come the methods from Objects class methods are visible in interface ?
...
When I tried to declare this method in interface, it says cannot override from Object class as it is declared as final method in Object class.
Helen Ma wrote:An abstract class has at least one method declaration without any implementation.
Helen Ma wrote:So, if an abstract class extends Object, an interface can also overrides the toString / equals/ hashCode methods from Objects.
Joanne
Niranjan Welankiwar wrote:If interface does not extends Object class then can please someone explain me the below code :
1.
interface a{
@Override
public int hashCode();
@Override
public String toString();
}
In above case, "a" interface is the new interface declared. Yet, no class is implementing it. Then how come the methods from Objects class methods are visible in interface ?
2. If it doesn't extends Object class, then why I can't declare below method in interface ?
public Class getClass();
When I tried to declare this method in interface, it says cannot override from Object class as it is declared as final method in Object class.
If an interface has no direct superinterfaces, then the interface implicitly declares a public abstract member method m with signature s, return type "r", and throws clause t corresponding to each public instance method m with signature s, return type "r", and throws clause t declared in Object, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface.
It is a compile-time error if the interface explicitly declares such a method m in the case where m is declared to be final in Object.
It follows that is a compile-time error if the interface declares a method with a signature that is override-equivalent (ยง8.4.2) to a public method of Object, but has a different return type or incompatible throws clause.
Tell the difficulties that i am difficult.
The only thing that kept the leeches off of me was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|