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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值