Object Oriented Programming Using Java - BEU CSE 3rd Semester
10 important Java OOP multiple-choice questions covering Java fundamentals, JVM, arrays, classes, objects, inheritance, interfaces, polymorphism, multithreading and JDBC.
Q1.Java is an example of which type of programming language?
Explanation: Java source code is compiled into bytecode, which is executed by the JVM through interpretation or JIT compilation. Therefore, Java is commonly described as a hybrid language.
Q2.Which of the following is considered the native language of a computer?
Explanation: Machine language consists of binary instructions that a computer processor can execute directly.
Q3.Consider the following code: class Base { public static void main(String[] args) { System.out.println("Hello"); } } public class Test extends Base {} What happens when the Test class is executed?
Explanation: Static methods can be inherited by subclasses. The main() method of Base is accessible when executing Test, so Hello is printed.
Q4.Consider the following Java code: int[] a = {1}; void increment(int[] i) { i[i.length - 1]++; } After calling increment(a), what will be the value of a[0]?
Explanation: The array reference is passed by value, but it refers to the same array object. Modifying its element inside the method changes the original array.
Q5.Consider the following statements: long longArr[]; int intArr[] = {7, 8, 9}; longArr = intArr; What will happen?
Explanation: Java does not support direct assignment of an int array to a long array. Array types are not automatically converted even when individual primitive values can be widened.
Q6.Consider the following Java code: interface A { void aMethod(); } class Test implements A { void aMethod() { System.out.println("Hello"); } } What will happen during compilation?
Explanation: Interface methods are implicitly public. The implementing method must also be public. Using default access in the implementing class causes a compilation error.
Q7.Which of the following concepts represents runtime polymorphism in Java?
Explanation: Method overriding allows a subclass to redefine an inherited method. The method implementation is selected at runtime based on the actual object type.
Q8.Which of the following is the correct way to create an object of class Box in Java?
Explanation: The new keyword creates an object and invokes its constructor. The reference variable stores the reference to the newly created object.
Q9.Which method of the Thread class is used to temporarily pause the execution of the currently executing thread?
Explanation: Thread.sleep() pauses the currently executing thread for a specified period. It is a static method of the Thread class.
Q10.Which of the following is a major advantage of using PreparedStatement in JDBC?
Explanation: PreparedStatement separates SQL instructions from parameter values. Parameterized queries help prevent SQL injection and can improve query execution efficiency.