如何在同一包的另一个类中调用方法?

问题描述:

如何调用方法,该方法位于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?

创建Class B的实例:

Create an instance of Class B:

B b=new B();
b.method();

或在B类中定义静态方法:

or define an static method in Class B:

class B
{
 static void staticMethod();
}

并这样称呼它:

B.staticMethod();