本文介绍了静态和非静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们不能使用具有相同名称的静态和非静态方法...?

这背后的原因是什么,即使我们使用不同的调用机制作为



class_name.static_method();









instance.non-static_method();

Why we can't have a static and a non-static method with same name...?
Whats the reason behind this even we use different calling mechanism for both as

class_name.static_method();

and


instance.non-static_method();

推荐答案


Foo.method1()

。如果您尝试使用method2,它将失败。但这样可行:

. If you try that with method2, it will fail. But this will work:

Foo bar = new Foo(1);
bar.method2();



这篇关于静态和非静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 21:24
查看更多