VERSION 1 //cant use this or super in body of static method
class Test1 extends Test{
static
String string1 = "string1";
public static void main(String[] args) {
Test1 test1 = new Test1();
Test.method1();
((
Test)test1).method1();
//super.method1(); //undefined variable, class or package name: super
test1.method1();
//this.method1(); //undefined variable, class or package name: this
}
static void method1() {
System.out. println("Test1");
}
}
class Test {
static void method1() {
System.out.println("Test");
}
}
VERSION 2 //variable test1 is out of scope
class Test1 extends Test{
static String string1 = "string1";
public static void main(String[] args) {
Test1 test1 = new Test1();
test1.method2();
}
static void method1() {
System.out. println("Test1");
}
void method2() {
Test.method1();
//((Test)test1).method1(); //undefined variable, class or package name: test1
super.method1();
//test1.method1(); //undefined variable, class or package name: test1
this.method1();
}
}
class Test {
static void method1() {
System.out.println("Test");
}
}