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. A getter function

  2. A setter function

  3. A constructor

  4. An overridden method

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

A mutator method, commonly known as a setter, is used to modify the state of an object by changing the value of its private fields.

Multiple choice
  1. Only its own class can access it

  2. Any class can access it

  3. Only its package can access it

  4. Only its subclasses can access it

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

The 'private' access modifier restricts visibility so that the member can only be accessed within the class where it is declared.

Multiple choice
  1. The process of negating methods from a super class.

  2. The process of restoring orphaned objects.

  3. The process of de-allocating memory automatically.

  4. The process of creating a new object.

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

Garbage collection in Java is an automatic memory management process that identifies and discards objects that are no longer needed by the application, thereby freeing up memory resources. This prevents memory leaks without requiring manual de-allocation by the developer.

Multiple choice
  1. List

  2. Map

  3. Set

  4. Queue

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

In the Java Collections Framework, java.util.Map is a self-contained interface that models key-value mappings and does not extend the java.util.Collection interface. In contrast, List, Set, and Queue all extend Collection.

Multiple choice
  1. The interface that all java collections implement

  2. A class filled with static methods used to manipulate collections

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

java.util.Collections is a utility class in Java that consists entirely of static methods that operate on or return collections (such as sorting, searching, or making them thread-safe). The interface that collection classes implement is java.util.Collection (singular).

Multiple choice
  1. True

  2. False

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

In Java, you can declare a class as abstract even if it contains only concrete methods (methods with implementations) and no abstract methods. This is typically done to prevent the class from being instantiated directly, forcing users to subclass it.

Multiple choice
  1. True

  2. False

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

Private members of a class are only accessible within the class in which they are declared. Even though a subclass inherits all members of its superclass, it cannot directly access private fields or methods. Instead, it must use public or protected getter and setter methods to interact with them.

Multiple choice
  1. Method with different number or type of parameters

  2. When the JVM overrides your calls for Garbage Collection.

  3. None of the Above

  4. Same method signature but different implementation

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

Method overriding occurs when a subclass provides a specific implementation for a method that is already defined in its superclass. The overriding method must have the exact same name, return type, and parameter list (signature) as the method in the parent class. This allows for runtime polymorphism.