Discussion Forum : Introduction To Methods And Streams
Question -


What is the output of this program?


final class A {
int i;
}
class B extends A {
int j;
System.out.println(j + " " + i);
}
class inheritance {
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
Options:
A .  2 2
B .  3 3
C .  Runtime Error
D .  Compilation Error
Answer: Option D

class A has been declared final hence it cannot be inherited by any other class. Hence class B 

does not have member i, giving compilation error.
output:
$ javac inheritance.java
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
i cannot be resolved or is not a field



Was this answer helpful ?
Next Question
Submit Your Solution hear:

Your email address will not be published. Required fields are marked *