Question 1
What is the use of final keyword in Java?
When a class is made final, a subclass of it can not be created.
When a method is final, it can not be overridden.
When a variable is final, it can be assigned value only once.
All of the above
Question 2
class Main {
public static void main(String args[]){
final int i;
i = 20;
System.out.println(i);
}
}
Question 3
Output of the below Java Code?
class Main {
public static void main(String args[]){
final int i;
i = 20;
i = 30;
System.out.println(i);
}
}
30
Compiler Error
Garbage value
0
Question 4
Output of the below Java Code?
class Base {
public final void show() {
System.out.println("Base::show() called");
}
}
class Derived extends Base {
public void show() {
System.out.println("Derived::show() called");
}
}
public class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
Derived::show() called
Base::show() called
Compiler Error
Exception
There are 4 questions to complete.