是的,我們可以在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中文網其他相關文章!