Question 2
Question 2
Question 2
A) Private
B) Protected
C) Public
D) Package-private (default)
A) new
B) create
C) make
D) instantiate
5. Which loop will always execute its body at least once regardless of the condition?
A) for loop
B) while loop
C) do-while loop
D) None of the above
A) while loop checks the condition before execution; do-while loop checks it after
execution
B) do-while loop checks the condition before execution; while loop checks it after
execution
C) while loop executes the code block once; do-while loop can execute it multiple
times
D) There is no difference between them
A) Using return
B) Using continue
C) Using break
D) Using stop
8. In a for loop, what happens if the increment expression is omitted?
11. Which keyword is used to call a constructor from another constructor in the
same class?
A) call
B) this
C) super
D) new
A) It initializes a variable
B) It calls the parent class’s constructor
C) It defines a new constructor
D) It stops the execution of the constructor
A) It initializes a variable
B) It calls the parent class’s constructor
C) It defines a new constructor
D) It stops the execution of the constructor
15. System.out.println(7 / 2);
A) 3.5
B) 3
C) 3.0
D) 7
20. Which keyword is used to define a method that does not return a value?
A) int
B) void
C) null
D) static
Answer: B) Using the same method name with different parameter lists
A) Main
B) Scanner
C) Calculator
D) MyClass
Answer: B) Scaner
A) 4 times
B) 5 times
C) 6 times
D) 0 times
28. int i = 0;
while (i < 3) {
System.out.println(i);
i++;
}
A) 1 2 3
B) 0 1 2 3
C) 0 1 2
D) 3 2 1 0
29. Which of the following is true about the for-each loop in Java?
32 Which of the following logical operators is used to check if both conditions are true
in an if statement?
A) ||
B) &&
C) !
D) = =
33. Which of the following statements correctly describes the use of continue in a while
loop?
Answer: C) It skips the rest of the current iteration and continues with the next iteration.
34. int count = 0; while (count < 5) { if (count == 2) { break; } System.out.println(count); count++; }
A) 0 1
B) 0 1 2 3 4
C) 0 1 2
D) 0 1 3 4
Answer: C) The bundling of data and methods that operate on that data within one unit
A) Hiding the internal implementation details and showing only essential features
B) The process of defining multiple classes with the same name
C) The ability to define private variables
D) The ability to create an instance of a class
Answer: A) Hiding the internal implementation details and showing only essential features