Re: About Question enthuware.ocpjp.v17.2.3698
Posted: Sun Oct 20, 2024 10:19 pm
Hi
For the first option as given below:
----------------------------------------------------
record Student(int id, String... subjects){
@Override
public int id(){
return 10; }
@Override
public boolean equals(Object obj){
return false;
}
}
-------------------------------------------------
first @Override annotation isn't making sense to me though it's compiling fine in IntelliJ.
AFAIK, direct supertype of this Student record is java.lang.Record which doesn't have any member method id(). Hence, Student record isn't overriding id() but declaring/defining it.
Can you please explain why first @Override annotation is not throwing any error?
Thanks
For the first option as given below:
----------------------------------------------------
record Student(int id, String... subjects){
@Override
public int id(){
return 10; }
@Override
public boolean equals(Object obj){
return false;
}
}
-------------------------------------------------
first @Override annotation isn't making sense to me though it's compiling fine in IntelliJ.
AFAIK, direct supertype of this Student record is java.lang.Record which doesn't have any member method id(). Hence, Student record isn't overriding id() but declaring/defining it.
Can you please explain why first @Override annotation is not throwing any error?
Thanks