Code:
class SuperClass
{
int a = 111;
static int b = 222;
static void m1()
{
System.out.println(" Super class static method ");
}
void m2()
{
System.out.println(" Super class non-static method ");
}
}
class SubClass extends SuperClass
{
int a = 333; // Instance Variable
static int b = 444; // Class Variable
static void m1()
{
System.out.println(" Sub class static method ");
}
void m2()
{
int a = 555; // Local Variable
System.out.println(" Sub class non-static method ");
System.out.println(" Local a: "+ a );
System.out.println(" Class a: "+ this.a );
System.out.println(" Super Class a: "+ super.a );
m1();
super.m1();
super.m2();
}
}
class Demo
{
public static void main( String args[] )
{
SubClass sc = new SubClass();
sc.m2();
}
}
class SuperClass
{
int a = 111;
static int b = 222;
static void m1()
{
System.out.println(" Super class static method ");
}
void m2()
{
System.out.println(" Super class non-static method ");
}
}
class SubClass extends SuperClass
{
int a = 333; // Instance Variable
static int b = 444; // Class Variable
static void m1()
{
System.out.println(" Sub class static method ");
}
void m2()
{
int a = 555; // Local Variable
System.out.println(" Sub class non-static method ");
System.out.println(" Local a: "+ a );
System.out.println(" Class a: "+ this.a );
System.out.println(" Super Class a: "+ super.a );
m1();
super.m1();
super.m2();
}
}
class Demo
{
public static void main( String args[] )
{
SubClass sc = new SubClass();
sc.m2();
}
}
Output: