java super var

Solutions on MaxInterview for java super var by the best coders in the world

showing results for - "java super var"
Carson
26 Apr 2020
1class Superclass
2{
3   int num = 100;
4}
5class Subclass extends Superclass
6{
7   int num = 110;
8   void printNumber(){
9	/* Note that instead of writing num we are
10	 * writing super.num in the print statement
11	 * this refers to the num variable of Superclass
12	 */
13	System.out.println(super.num);
14   }
15   public static void main(String args[]){
16	Subclass obj= new Subclass();
17	obj.printNumber();	
18   }
19}