一、调用的是静态类
可以用类名直接调用,调用格式:类名.方法名(参数表)
public class StaticCall {
public static void staticCall(){
System.out.println("Successfully called the method in the static class");
}
}
public class Main {
public static void main(String[] args) {
StaticCall.staticCall();
}
}
成功输出
调用的是非静态类
将类实例化后调用
public class NotStaticCall {
public void notStaticCall(){
System.out.println("Successfully called the method in the non static class");
}
}
public class Main {
public static void main(String[] args) {
/*
调用非静态类中的方法
*/
NotStaticCall nSC=new NotStaticCall();
nSC.notStaticCall();
}
————————————————
版权声明:本文为CSDN博主「Esrs」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hahaha8129/article/details/108852238