Home >Java >javaTutorial >In Java, can we declare main() method as final?
Yes, we can declare the main() method as final in Java. The compiler won't throw any errors.
class BaseClass { public final void show(Object o) { System.out.println("BaseClass method"); } } class DerivedClass extends BaseClass { public void show(Integer i) { System.out.println("DerivedClass method"); } } public class Test { public static final void main(String[] args) { // declaring main () method with final keyword. BaseClass b = new BaseClass(); DerivedClass d = new DerivedClass(); b.show(new Integer(0)); d.show(new Integer(0)); } }
BaseClass method DerivedClass method
The above is the detailed content of In Java, can we declare main() method as final?. For more information, please follow other related articles on the PHP Chinese website!