✅ 25 High-Level MCQ Questions
Java Programming Construct
1. Which of the following best describes widening and narrowing conversions in
Java?
a) Both are implicit
b) Widening is implicit, narrowing is explicit
c) Both require casting
d) Widening requires casting
What is the output of the following code?
int a = 5;
System.out.println(++a + a++);
2. a) 11
b) 12
c) 10
d) 13
3. Which type of comment is used to generate documentation using javadoc?
a) //
b) /* */
c) /** */
d) <!-- -->
4. What happens if you declare a local variable with the same name as a class
member?
a) Compilation error
b) Runtime error
c) Local variable shadows the class member
d) Class member is used
5. Which of the following allows you to take multiple types of input in a single line
using Scanner?
a) next()
b) nextLine()
c) hasNext()
d) next<Type>() methods in sequence
Java Control Flow
6. What is the purpose of labeled break in Java?
a) Exit switch block
b) Exit a specific loop
c) Exit method
d) Restart loop
7. What is the key difference between while and do-while loops?
a) Syntax
b) do-while always executes once
c) while uses counter
d) do-while doesn't check condition
8. Which of the following statements is true about short-circuit evaluation?
a) Both sides are always evaluated
b) Only first operand is evaluated
c) Second operand is skipped if not needed
d) It's used only in ternary operators
9. Given a switch statement without a break, what is the behavior called when all
subsequent cases execute?
a) Jump
b) Skip
c) Fall-through
d) Skip-through
What will be the result of this code?
int x = 10;
if (x == 10)
if (x < 15)
System.out.println("x < 15");
else
System.out.println("x > 15");
10. a) x < 15
b) x > 15
c) Compilation error
d) No output
Java Arrays
11.Which of the following can dynamically resize during runtime?
a) Array
b) ArrayList
c) HashMap
d) LinkedList
12.What will int[] a = new int[5]; System.out.println(a[5]); output?
a) 0
b) null
c) ArrayIndexOutOfBoundsException
d) Compilation error
13.What is the default value of elements in a boolean[] array?
a) true
b) false
c) null
d) 0
14.How do you copy an array manually in Java?
a) System.copy(a, b)
b) array.clone()
c) System.arraycopy()
d) Collections.copy()
15.How many total elements in int[][] arr = new int[3][4];?
a) 7
b) 12
c) 3
d) 4
16.Which best describes a jagged array?
a) 2D array with different row sizes
b) Multi-dimensional equal-sized arrays
c) Arrays with null values
d) Circular arrays
17.What happens when we modify an array through a method?
a) It affects the original array
b) Only a copy is changed
c) Compilation error
d) Only the first element changes
18.Which loop is best suited for iterating over arrays where indexes are not needed?
a) while
b) for loop
c) for-each
d) do-while
Java Methods
19.What is method overloading?
a) Having two methods with different return types
b) Having two methods with same name but different parameters
c) Two methods with different access specifiers
d) None of the above
20.Which is true for a method that does not return anything?
a) Must return null
b) Cannot use return statement
c) Return type is void
d) Should be private
21.Which of the following is a valid static method usage?
a) Can access instance variables
b) Can call from another class without object
c) Can override in subclass
d) None of the above
22.Which library class has a method for absolute value?
a) Math.abs()
b) Integer.abs()
c) Math.absolute()
d) Number.abs()
23.What does the return keyword do inside a method?
a) Terminates method
b) Exits class
c) Skips loop
d) Repeats execution
24.What is the scope of a variable declared inside a method?
a) Whole class
b) Package
c) Only within the method
d) Inherited to subclasses
25.What is the main advantage of using methods in code?
a) Speed
b) Redundancy
c) Modularity and reusability
d) Compilation time
✅ 20 High-Level Coding Questions
Java Programming Construct & Control Flow
1. Write a program to simulate a basic calculator (add, subtract, multiply, divide)
using switch.
2. Create a program that takes a user's input name and age, then checks if the
person is eligible to vote (age >= 18).
3. Write a method that takes three integers and returns the greatest among them.
4. Take two integers and a character (‘+’, ‘-’, ‘*’, ‘/’) from the user. Perform the
operation based on the character.
5. Write a program to convert temperature from Celsius to Fahrenheit using a
method.
Java Arrays
6. Write a program that finds the maximum and minimum values in an array.
7. Sort an integer array in ascending order without using built-in sort functions.
8. Write a program to count the frequency of each element in an array.
9. Take an array from the user and print only the duplicate elements.
10.Write a method that merges two sorted arrays into one sorted array.
11.Write a program to rotate an array to the right by k steps.
12.Create a program to check whether two arrays are equal.
13.Write a program to reverse each row in a 2D array.
14.Given a matrix, write a method to transpose it.
Java Methods
15.Create a method to check if a given number is a palindrome.
16.Write a method that returns the factorial of a number.
17.Write a method that checks whether a given string is a palindrome.
18.Write a method that returns the sum of digits of a given number.
19.Write a method that accepts an array and returns the second largest number.
20.Write a program that implements method overloading for area calculation (circle,
rectangle, triangle).