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
B.java
Output
Happy Coding :)
B.java
class A { static int x; } class B extends A { int x; void display() { System.out.println("Static variable x: "+super.x); System.out.println("Normal variable x: "+x); } public static void main(String arg[]) { A a=new A(); a.x=56; B b=new B(); b.x=44; b.display(); } }
Output
by Practical Server |
Happy Coding :)
0 Comments
Post a Comment