Java Programming - MCQ Practice Questions
Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.
958 questions | 100% Free
Consider the code: int a = 5; int b = a++; System.out.println(a + " " + b); What is the output?
What will be printed? System.out.println(10 + 20 + "Java");
What is the scope of a local variable in Java?
Consider: int x = 0; System.out.println(x == 0 && x != 1); What is the output?
What is the result of: int x = 5; System.out.println(x++ + ++x);?
Which statement about Java's garbage collection is true?
What will be the output? class Test { public static void main(String[] args) { int x = 10; { int x = 20; System.out.println(x); } System.out.println(x); } }
Which of the following will throw a NullPointerException? String s = null; System.out.println(s.length());
Consider: class Parent { Parent() { System.out.println("P"); } } class Child extends Parent { Child() { System.out.println("C"); } } public static void main(String[] args) { new Child(); }
What is the output of: int x = 5; System.out.println(x++ + ++x);
What will be the output of: int x = 5; System.out.println(++x + x++);?
What is the result of: System.out.println('A' + 'B');?
What will happen in this code: int x = Integer.MAX_VALUE; x++;?
In the context of Java 2024-25 exam pattern, which statement about the enhanced 'var' keyword (local variable type inference) is INCORRECT?
What is the output of the following code snippet? int x = 10; int y = x++ + ++x; System.out.println(x + " " + y);
What will be the result of executing the following code? boolean result = (5 > 3) && ( > 5); System.out.println(result);