+ 1
void methods declared with the final keyword does what?
sample code: ______________________________ public final void setName(String name) { this.name = name; } ______________________________ since void doesn't return any value, then why can the final keyword be used with it? I don't really get it.
2 Respostas
+ 5
the final keyword ensures a method cannot be overridden whether void or not
+ 3
Brains is right, if you would try to override the method in the subclass that would give an error, for example...
class A {
public final void a() {}
}
class B extends A {
public final void a() {} //Error
}