Examveda
Examveda

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);
      }
}

A. 15

B. 20

C. 30

D. Compiler Error

E. None of these

Answer: Option D

Solution(By Examveda Team)

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


This Question Belongs to Java Program >> Inheritence

Join The Discussion

Comments ( 1 )

  1. Vishal Lakra
    Vishal Lakra :
    4 years ago

    In java language final is a keyword . it restrictions on class , methods and variable.
    in this case we use super keyword.

Related Questions on Inheritence

What is inheritance in Java?

A. The process of acquiring properties and behaviors of one class by another

B. The process of creating objects

C. The process of encapsulation

D. The process of overloading methods