Java final keyword Read Discuss Courses Java final keyword Please wait while the activity loads. If this activity does not load, try refreshing your browser. Also, this page requires javascript. Please visit using a browser with javascript enabled. If loading fails, click here to try again 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 Java final keyword 50 Java Language MCQs with Answers Discuss itQuestion 1-Explanation: See final in Java. Question 2Output of following Java program class Main { public static void main(String args[]){ final int i; i = 20; System.out.println(i); } } 20Compiler Error0Garbage valueJava final keyword 50 Java Language MCQs with Answers Discuss itQuestion 2-Explanation: There is no error in the program. final variables can be assigned value only once. In the above program, i is assigned a value as 20, so 20 is printed.Question 3 class Main { public static void main(String args[]){ final int i; i = 20; i = 30; System.out.println(i); } } 30Compiler ErrorGarbage value0Java final keyword 50 Java Language MCQs with Answers Discuss itQuestion 3-Explanation: i is assigned a value twice. Final variables can be assigned values only one. Following is the compiler error "Main.java:5: error: variable i might already have been assigned"Question 4 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() calledBase::show() calledCompiler ErrorException Java final keyword 50 Java Language MCQs with Answers Discuss itQuestion 4-Explanation: compiler error: show() in Derived cannot override show() in Base 1 There are 4 questions to complete. You have completed questions question Your accuracy is Correct Wrong Partial-Credit You have not finished your quiz. If you leave this page, your progress will be lost. Correct Answer You Selected Not Attempted Final Score on Quiz Attempted Questions Correct Attempted Questions Wrong Questions Not Attempted Total Questions on Quiz Question Details Results Date Score Hint Time allowed minutes seconds Time used Answer Choice(s) Selected Question Text Need more practice! Keep trying! Not bad! Good work! Perfect! Last Updated : 25 Oct, 2021