Select the correct answerWhat will be the output of the following Java program?class conditional_statements { public static void main(String args[]) { final int u=10,v=20; while(u<v) { System.out.println("Good"); } System.out.println("Morning"); } }OptionsGoodGood Morningcompile time errorrun time error
Question
Select the correct answerWhat will be the output of the following Java program?class conditional_statements { public static void main(String args[]) { final int u=10,v=20; while(u<v) { System.out.println("Good"); } System.out.println("Morning"); } }OptionsGoodGood Morningcompile time errorrun time error
Solution
The correct answer is "compile time error".
Here's why:
The condition in the while loop while(u<v) is always true because the values of u and v are final and cannot be changed. This results in an infinite loop where "Good" would be printed out indefinitely. However, Java recognizes this at compile time and throws a compile time error, preventing the program from running.
Similar Questions
rect answerWhat will be the output of the following Java code? class Codetantra { public static void main(String args[]) { try { System.out.print("Good" + " " + 1 / 0); } finally { System.out.print("Morning"); } } }
Select the correct answerWhat will be the output of the following Java code? class Codetantra { public static void main(String args[]) { try { System.out.print("Good" + " " + 1 / 0); } finally { System.out.print("Morning"); } } }OptionsGoodCompilation ErrorFirst "Morning" then "Exception"Morning
Select the correct answerWhat will be the output of the following Java program?class main_class { public static void main(String args[]) { int code = 10; if (code == 10) { int code = 6; System.out.println(code); } } }OptionsCompilation error610Runtime error
Select the correct answerWhat is the output of following Java program?import static java.lang.System.*;class ProgrammingInJava { public static void main(String args[]) { out.println("Welcome!"); }}OptionsRuntime ErrorCompiler ErrorWelcome!None of these
Select the correct answerWhat will be the output of the following Java program?class java { public static void main(String args[]) { int w = 5; int x = 10; first: { second: { third: { if (w == x >> 1) break second; } System.out.println(w); } System.out.println(x); } } }Options5 1051010 5
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.