开发者

Can we call main() method of the Parent from a subclass in java?

we know that static members are available to their subclasses as well depending on their access modifier.

So i have following classes as:

            public class A {

            public static void main(String[] args){
            //.....
            }
            }

            public class B extends A{
            //....
            }

So i开发者_如何学编程 wanted to know that if run class B. will it run through the main method available for it through inheritance. if not Why?


Yes. If you run it, It'll execute parent class' main method.
The static method will'be inherited but can't be overriden.
If you define any static method with same name in subclass it'll only hide the parent method not override it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜