Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1069 :

Posted: Sun Sep 16, 2012 12:38 pm
by ByteByteByte
The explanation for option 4 says that 'final only means that subclasses cannot override it' but the method also has the static modifier which means it can not be overridden. :shock:

Re: About Question enthuware.ocajp.i.v7.2.1069 :

Posted: Mon Sep 17, 2012 9:11 am
by admin
The purpose of final is to prevent overriding. For example, if you try to compile the following code that tries "override" as final static method, the error message also calls it overriding:

Code: Select all

class X{
 public final static void m1(){ }
}
public class Test extends X
{
 public final static void m1(){ }
}

Test.java:6: m1() in Test cannot override m1() in X; overridden method
 is static final
 public final static void m1(){ }
                          ^
1 error
But the right terminology in case of a static method is "shadowed". The explanation should be modified to avoid such confusion.

thank you for your feedback!