是的,我们可以在Java中将main()方法声明为final。编译器不会抛出任何错误。
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
以上是在Java中,我们可以将main()方法声明为final吗?的详细内容。更多信息请关注PHP中文网其他相关文章!