Java / final keyword
Can a static method be final in Java?
Yes, you can make a static method final in Java.
When we declare a static method as final its prevents from method hiding and encounters compile time error: Cannot override the final method from Parent.
public class Parent { final static void helloWorld() { System.out.println("Hello from Parent."); } } class Child extends Parent { // compile error : Cannot override the final method from Parent static void helloWorld() { System.out.println("Hello from child."); } }
More Related questions...