_Java - MCQ Questions Coding Questions High Level
_Java - MCQ Questions Coding Questions High Level
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
2. a) 11
b) 12
c) 10
d) 13
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
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
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
Java Arrays
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
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.
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.
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.
Java Methods
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).