Write an application that illustrates how to access a hidden variable. Class A declares a static variable x. The class B extends A and declares an instance variable x. display( ) method in B displays both of these variables.
AIM: Write an application that
illustrates how to access a hidden variable. Class A declares a static variable
x. The class B extends A and declares an instance variable x. display( ) method
in B displays both of these variables.
CODE:
class
A{
static int x = 10;
}
class
B extends A{
int x = 20;
void display(){
System.out.println("X
of A: "+A.x);
System.out.println("X
of A: "+super.x);
System.out.println("X
of B: "+x);
System.out.println("X
of B: "+this.x);
}
}
class
p20{
public static void main(String args[]){
B b = new B();
b.display();
}
}
OUTPUT:

Comments
Post a Comment