iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.1Hard

Consider the code: int a = 5; int b = a++; System.out.println(a + " " + b); What is the output?

Q.2Hard

What will be printed? System.out.println(10 + 20 + "Java");

Q.3Hard

What is the scope of a local variable in Java?

Q.4Hard

Consider: int x = 0; System.out.println(x == 0 && x != 1); What is the output?

Q.5Hard

What is the result of: int x = 5; System.out.println(x++ + ++x);?

Q.6Hard

Which statement about Java's garbage collection is true?

Q.7Hard

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); } }

Q.8Hard

Which of the following will throw a NullPointerException? String s = null; System.out.println(s.length());

Q.9Hard

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(); }

Q.10Hard

What is the output of: int x = 5; System.out.println(x++ + ++x);

Q.11Hard

What will be the output of: int x = 5; System.out.println(++x + x++);?

Q.12Hard

What is the result of: System.out.println('A' + 'B');?

Q.13Hard

What will happen in this code: int x = Integer.MAX_VALUE; x++;?

Q.14Hard

In the context of Java 2024-25 exam pattern, which statement about the enhanced 'var' keyword (local variable type inference) is INCORRECT?

Q.15Hard

What will be the result of executing the following code?
boolean result = (5 > 3) && ( > 5);
System.out.println(result);