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. True

  2. False

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

Abstract classes are designed to be incomplete and cannot be directly instantiated using the 'new' keyword. They serve as templates for subclasses and must be extended before their functionality can be used. Only concrete subclasses of abstract classes can be instantiated.

Multiple choice
  1. interface

  2. child class

  3. base class

  4. listener

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

The 'extends' keyword in Java is used for inheritance and is always followed by the base class (parent class) name. The child class inherits properties and behaviors from the base class, establishing an 'is-a' relationship between them.

Multiple choice
  1. base ()

  2. parent ()

  3. super ()

  4. none of the above

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

The super() call is used in Java to invoke the constructor of the base (parent) class from a child class constructor. This allows the child class to initialize inherited properties and behaviors defined in the parent class, ensuring proper initialization throughout the inheritance chain.

Multiple choice
  1. is not allowed

  2. cannot have a constructor

  3. cannot have a destructor

  4. cannot be passed as an argument

Reveal answer Fill a bubble to check yourself
A Correct answer
Multiple choice
  1. Class

  2. Inheritance

  3. Polymorphism

  4. Aggregation

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

A class serves as a blueprint or template that defines the structure and behavior common to all objects of that type. It specifies what data (variables/attributes) and operations (methods/functions) every object created from that class will have. Objects are instances created from this blueprint.

Multiple choice
  1. method overloading

  2. method invocating

  3. method overriding

  4. method labeling

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

Method overloading allows a class to have multiple methods with the same name but different parameter lists (different number or types of parameters). The compiler selects which version to call based on the arguments passed. This is different from overriding (replacing a parent class method) and enables method behavior to vary based on input types.

Multiple choice
  1. III and IV

  2. I and II

  3. II and III

  4. I and IV

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

Constructors have the same name as their class (statement II is true) and can be overloaded to provide multiple initialization options (statement III is true). Statement I is false because while constructors have no return type, they are not void methods. Statement IV is false because constructors are called automatically during object creation, not like regular methods.