java的main方法能不能被子类继承

      题记:今天是被顺子问到这个问题,当时自己回答是能,因为潜意识我是觉得所有的方法都可以被继承的。但我也不是很确定,因为我觉得main比较特殊,它必须为public static void ,JVM在运行类的时候,会调用它!所以回来后上网搜了下!仅供参考!

 

 

     首先,这是sun的Java Tutorial中的说法:

A subclass inherits all the member variables and methods from its superclass. However, the subclass might not have access to an inherited member variable or method. For example, a subclass cannot access a private member inherited from its superclass. One might think, then, that the item was not inherited at all. But the item is inherited. This becomes important when using an inner class, which does have access to its enclosing class's private members. Note that constructors are not members and so are not inherited by subclasses.

简要说就是子类可以继承父类所有的属性和方法,只是对于私有的不能访问~

还有最后一句说构造函数不是类的成员,所以不会被子类继承~(这个不太清楚~构造函数不是类的成员?)

      关于这个问题的讨论,大家可以看下这个贴子:http://topic.csdn.net/u/20080805/11/83d5913f-1ce0-40f7-ac0c-56b55a43423f.html

你可能感兴趣的:(Java)