ExamVeda
Login
Home
This question belongs to Java Program Inheritence
Inheritence
?

What will be the output?
class One{
      final int a = 15;
}

class Two extends One{
      final int a = 20;
}

public class Test extends Two{
      final int a = 30;

      public static void main(String args[]){
            Test t = new One();
            System.out.print(t.a);
      }
}

Answer & Solution
Correct Answer: Option D

We can't store super class object in subclass reference But we can store subclass object in super class reference.

Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Vishal Lakra
Vishal Lakra 7 years ago
In java language final is a keyword . it restrictions on class , methods and variable.
in this case we use super keyword.