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 technology
  1. (a) Data-Operator-Party

  2. (b) Data-Party-Operator

  3. (c) Party-Data-Operator

  4. (d) Party-Operator-Data

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

In Pega's party model, 'Data-Party-Operator' is the standard class used for representing an Originator party. The naming convention follows the pattern Data-Party-XXX where XXX identifies the party type. The other options reverse this order incorrectly.

Multiple choice technology programming languages
  1. I am a constructor of A,I am a destructor of A,I am a constructor of B,I am a destructor of B

  2. I am a constructor of A,I am a constructor of B,I am a destructor of A,I am a destructor of B

  3. I am a constructor of A,I am a constructor of B,I am a destructor of B,I am a destructor of A

  4. I am a destructor of B,I am a constructor of A,I am a destructor of A,I am a constructor of B

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

When objects are created on the stack, constructors execute in order of declaration (a1 first, then b1). When main() returns, destructors execute in reverse order (b1's destructor first, then a1's), following the LIFO (Last In, First Out) principle of stack unwinding.

Multiple choice technology programming languages
  1. To access derived class objects using base class pointer.

  2. To access base class objects using derived class pointer.

  3. To avoid ambiguity in inheritance.

  4. To create array of objects.

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

Virtual functions enable runtime polymorphism. When you call a virtual function through a base class pointer, the actual derived class implementation is executed based on the object's dynamic type, not the pointer's static type. This allows base class pointers to correctly invoke derived class behavior.

Multiple choice technology web 2.0
  1. Call the ISAssembly property of the MethodInfo Class

  2. Call the ISstatic property of the MethodInfo Class

  3. Call the ISvirtual property of the MethodInfo Class

  4. Call the ISFamily property of the MethodInfo Class

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

When using reflection in .NET to inspect method accessibility, the IsFamily property of the MethodInfo class indicates whether a method is accessible to derived classes (i.e., it's protected or family-access). This property returns true for protected methods, which can be called by derived classes but not from outside the class hierarchy. IsAssembly checks internal access, IsStatic checks for static methods, and IsVirtual checks for virtual methods - none of these indicate inheritance accessibility.

Multiple choice technology web 2.0
  1. System.Object

  2. System.string

  3. System.Stringbuilder

  4. System.Clone

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

In the .NET Framework, System.Object is the ultimate base class from which all other classes derive. Every class in .NET, either directly or indirectly, inherits from System.Object. This provides common functionality like ToString(), Equals(), GetHashCode(), and MemberwiseClone() to all objects. System.String and System.StringBuilder are derived classes, and System.Clone is not a base class but rather a method that objects can implement via ICloneable interface.

Multiple choice technology programming languages
  1. Only A & B

  2. Only B & C

  3. Only A & C

  4. A,B and C

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

A final class is restricted from being inherited or subclassed (A). An abstract class cannot be instantiated directly using the new keyword (B). However, abstract classes can and are intended to be inherited by concrete subclasses (C), making all statements true.

Multiple choice technology programming languages
  1. Inheritance

  2. Polymorphism

  3. Abstraction

  4. Modularization

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

IS-A relationship represents inheritance where a subclass 'is a' type of its superclass. For example, a Car IS-A Vehicle. Polymorphism enables method flexibility, abstraction hides complexity, and modularization divides systems into components.

Multiple choice technology programming languages
  1. Implement a no-argument constructor

  2. provide an identifier property

  3. declare accessors for persistent fields

  4. all the above

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

Hibernate requires a no-argument constructor to instantiate objects via reflection when retrieving data from the database. While identifier properties and accessors are best practices, they are not mandatory for basic POJO functionality.

Multiple choice technology programming languages
  1. Table per Concrete class

  2. Table per Sub class

  3. Table per class Hierarchy

  4. all of the above

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

Hibernate supports three inheritance mapping strategies: Table per Concrete Class (each class gets its own table), Table per Subclass (shared parent table with separate subclass tables), and Table per Class Hierarchy (single table for entire hierarchy).