Computer Knowledge

Object-Oriented Programming

2,686 Questions

Object-oriented programming questions test core computer science concepts like classes, inheritance, polymorphism, and encapsulation. The focus includes Java program structures, method overloading, and memory allocation for objects. This topic is essential for technical sections in various recruitment tests.

Java class definitionsMethod overriding rulesPolymorphism conceptsGeneric type parametersMemory allocation in objects

Object-Oriented Programming Questions

Multiple choice
  1. class

  2. method

  3. interface

  4. none of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Runnable is a functional interface in Java that contains a single abstract method run(). Any class implementing Runnable must provide an implementation for the run() method, making it suitable for multithreading. The other options are incorrect because Runnable is not a class, method, or abstract concept - it's specifically an interface designed for thread execution.

Multiple choice
  1. java.security package

  2. java.util package

  3. java.io package

  4. java.lang package

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Wrapper classes like Integer, Double, Float, Character, and Boolean are part of the java.lang package, which is automatically imported in every Java program. These classes wrap primitive data types to allow them to be used as objects. The java.security, java.util, and java.io packages serve different purposes - security utilities, collections framework, and I/O operations respectively.

Multiple choice
  1. java.io

  2. java.util

  3. java.utility

  4. java.date

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The Date class is part of the java.util package, which contains utility classes and collections framework. While Date has been largely superseded by the newer java.time API in modern Java, it remains in java.util for backward compatibility. The other options like java.utility, java.date, or java.io are incorrect - Date has never been in those packages.

Multiple choice
  1. java.util

  2. java.io

  3. java.utility

  4. java.math

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Random class is part of java.util package and is used for generating pseudorandom numbers. It provides methods like nextInt(), nextDouble(), nextBoolean(), and nextFloat() for various random number types. This is different from Math.random() which returns a double value. Random is not in java.io, java.utility (doesn't exist), or java.math packages.

Multiple choice
  1. A virtual function must not be static.

  2. Destructor cannot be declared as virtual, but constructor can be declared as virtual.

  3. A virtual function may be declared as a friend for another class.

  4. Both 1 and 2

  5. Both 1 and 3

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Options 1 and 3 are correct. Option 2 is not correct because destructor can be declared as virtual, but constructor cannot be declared as virtual.