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

Popular posts from this blog

Write an application that illustrates method overriding in the same package and different packages. Also demonstrate accessibility rules in inside and outside packages

Describe abstract class called Shape which has three subclasses say Triangle, Rectangle, and Circle. Define one method area()in the abstract class and override this area() in these three subclasses to calculate for specific object.

Write a program in Java to perform I/O operations on a Text file.