

public class invokeMethod{
public void showMsg(){
System.out.println("this is showMsg");
}
public void callOther(){
showMsg();
}
public static void main(String args[]){
invokeMethod ob=new invokeMethod();
ob.callOther();
}
}
因有new invokeMethod(); 所以callOther及showMsg等可被调用,因为这些没有static声明的方法只有在实例化时才会创建,故需在main中对invokerMethod类进行实例化。若无实例化invokeMethod类,则在Main函数中用到在其它类函数,都必须声明为static,静态的。无意中解释了自己的一个小困惑。
原创文章,作者:苏葳,如需转载,请注明出处:https://www.swmemo.com/318.html
