Knowee
Questions
Features
Study Tools

What will be the output of the following Java program? class scopevariable { public static void main(String args[]) { int c; c = 15; { int d = 36; System.out.print(c + " " + d); } System.out.println(c + " " + d); } }Options5 6 55 6 5 6Runtime errorCompilation error

Question

What will be the output of the following Java program? class scopevariable { public static void main(String args[]) { int c; c = 15; { int d = 36; System.out.print(c + " " + d); } System.out.println(c + " " + d); } }Options5 6 55 6 5 6Runtime errorCompilation error

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the Java program will be a Compilation error. This is because the variable 'd' is declared inside a block and its scope is limited to that block only. When we try to access 'd' outside of its scope (in the last print statement), the compiler doesn't recognize 'd' and throws a compilation error.

Similar Questions

ct answerWhat will be the output of the following Java program? class scopevariable { public static void main(String args[]) { int c; c = 15; { int d = 36; System.out.print(c + " " + d); } System.out.println(c + " " + d); } }

What is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}OptionsCompiler Error30Garbage value0

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

What is the output of the following code?public class Solution { static int x = 10; public static void main(String args[]) { System.out.println(x); } }Options: Pick one correct answer from below100Compilation errorRuntime error

e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}

1/3

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.