Computer Knowledge

Object-Oriented Programming

2,239 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. 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.

Multiple choice
  1. When the class has no other constructors

  2. When you define at least one constructor with at least one parameter

  3. When you define at least one constructor

  4. none of the above

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

The Java compiler automatically provides a default, no-argument constructor only if no other constructors are explicitly defined in the class. If you write any constructor yourself, whether it has parameters or not, the compiler will not generate the default constructor.

Multiple choice
  1. myClass

  2. The_Classiest_Class

  3. MyClassyClass

  4. aniketsclasstoendallclasses

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

Java class naming conventions dictate using UpperCamelCase (PascalCase), where the first letter of each word is capitalized, and no underscores or special characters are used. 'MyClassyClass' perfectly adheres to this standard.

Multiple choice
  1. Has a specific function

  2. Has a general function

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

In biology, specialized cells or tissues are those that have developed unique structures to perform a specific function. Unlike general cells, they are highly adapted to carry out one particular job efficiently.