Select the correct answerPredict the output of following Java program.?class CT { public static void main(String args[]) { int a; System.out.println(a); } } Optionscompiler errorgarbage value0runtime error
Question
Select the correct answerPredict the output of following Java program.?class CT { public static void main(String args[]) { int a; System.out.println(a); } } Optionscompiler errorgarbage value0runtime error
Solution
The correct answer is "compiler error". In Java, local variables are not given a default value. The compiler does not have a default value to assign to 'a' and you haven't assigned it one either. Therefore, it will throw a compiler error.
Similar Questions
elect the correct answerPredict the output ?class Test { public static void main(String args[]) { int arr[] = new int[2]; System.out.println(arr[0]); System.out.println(arr[1]); }}OptionsCompiler Errorgarbage valuegarbage value00Exception
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 answerPredict the output of following Java program.class codetantra { public static void main(String[] args) { for(int i = 0; 0; i++) { System.out.println("Hello"); break; } } } OptionsCompiler errorEmpty OutputHelloRuntime error
Select the correct answerWhat will be the output of the following Java program? class CT { public static void main(String args[]) { try { int x, y; y = 0; x = 5 / y; System.out.print("A"); } catch(ArithmeticException e) { System.out.print("B"); } } }OptionsBACompilation ErrorRuntime Error
Select the correct answerWhat is the output of the following program?public class Test{ public static void main(String []args){ int i = 0; for(i = 0; i < 10; i++){ continue; } System.out.println(i); }}OptionsCompilation error0109
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.