如何调用同一个包的另一个类中的方法? [英] How to call a method in another class of the same package?
本文介绍了如何调用同一个包的另一个类中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何调用Java中同一个包的另一个类中的方法?我所知道的是,使用一个对象,我们可以调用来自不同类的方法.有没有其他方法可以调用不同类的方法?
How to call a method, which is in another class of same package in Java? What I know is, using an object we can call a method from a different class. Is there any other way to call a method of different class?
推荐答案
创建 B 类的实例:
B b=new B();
b.method();
或者在B类中定义一个静态方法:
or define an static method in Class B:
class B
{
static void staticMethod();
}
并这样称呼它:
B.staticMethod();
这篇关于如何调用同一个包的另一个类中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文