加载中...
加载中...
JAVA Main方法中调用非静态方法

JAVA Main方法中调用非静态方法 原创

在JAVA中在静态方法中只能调用其他静态方法,不能调用非静态方法,

main方法都是静态方法,如果想调用他的非静态方法,可以将当前类实例化然后再调用它的非静态方法。

复制收展Javapackage com.test.clas.protect;
import com.test.clas.SuperClass;
/**
* @Desc -累行客
* @Author luolei
* @Web http://www.leixingke.com/
* @Date 2020/08/07 08:50
*
*/
public class InvokeSuperMethod extends SuperClass {
public static void main(String[] args) {
InvokeSuperMethod invokeSuperMethod = new InvokeSuperMethod();
invokeSuperMethod.method();
}

public void method(){
super.protectedMethod();
System.out.println(super.protectedField);
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20


路由器章节测试1【单选题】以下哪个是基于距离矢量路由选择算法的路由协议?A、RIPB、OSPFC、EIGRPD、静态路由协议【解析】 RIP距离向量路由算法 OSPF链路状态路由算法 
为什么静态成员、静态方法中不能用this和super关键字?1.     在静态方法中是不能使用this预定义对象引用的,即使其后边所操作的也是静态成员也不行.因为
没有更多推荐了 [去首页]
image
文章
376
原创
293
转载
83
翻译
0
访问量
183398
喜欢
73
粉丝
5
码龄
7年
资源
3

文章目录

加载中...
1
0