在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