Exam Practice Questions And Correct
Answers (Verified Answers) Plus
Rationales 2025 Q&A | Instant
Download Pdf
1. Which of the following is a valid way to declare and initialize an array
in Java?
a) int arr = new int[5];
b) int[] arr = {1, 2, 3, 4, 5};
c) int arr[] = new int(5);
d) int arr = {1, 2, 3};
b) int[] arr = {1, 2, 3, 4, 5};
Arrays in Java are declared using square brackets, and initialization
can be done with curly braces containing values.
2. What is the default value of a boolean variable in Java?
a) true
b) false
c) 0
d) null
b) false
Boolean variables are initialized to false by default in Java.
,3. Which keyword is used to prevent inheritance in Java?
a) static
b) final
c) abstract
d) const
b) final
The final keyword prevents classes from being extended.
4. Which of the following is not a primitive data type in Java?
a) int
b) boolean
c) String
d) double
c) String
String is a class, not a primitive type in Java.
5. What will happen if you try to compile a class without a main method
in Java 8?
a) It will compile and run successfully.
b) It will compile but not run.
c) It will not compile.
d) It will throw a runtime error.
b) It will compile but not run.
Classes without main methods can compile but cannot be executed
directly.
6. Which access modifier makes a member accessible only within its
package?
a) private
b) protected
c) default (no modifier)
d) public
, c) default (no modifier)
Default access gives package-level visibility.
7. What is the size of an int in Java?
a) 16 bits
b) 32 bits
c) 64 bits
d) Platform-dependent
b) 32 bits
Java’s int is always 32 bits, independent of platform.
8. Which of the following statements about interfaces is true?
a) Interfaces can have constructors.
b) Interfaces can have instance fields.
c) Interfaces can have default methods.
d) Interfaces cannot be extended.
c) Interfaces can have default methods.
From Java 8 onward, interfaces can contain default methods.
9. Which exception is unchecked in Java?
a) IOException
b) SQLException
c) NullPointerException
d) ClassNotFoundException
c) NullPointerException
Runtime exceptions like NullPointerException are unchecked.
10. Which of the following is the correct way to create a thread?
a) Extend the Runnable class.
b) Implement the Thread interface.
c) Extend the Thread class or implement Runnable.
d) None of the above.
c) Extend the Thread class or implement Runnable.