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 programming languages
  1. Case 1 will compile and execute

  2. Case 2 will compile and execute

  3. Case 2 will compile but fail at runtime

  4. Both the Cases wont compile

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

Case 1 (B to A) is upcasting - a subclass reference can always be assigned to a superclass reference, so it compiles and runs. Case 2 (A to B) is downcasting - requires explicit cast syntax B b=(B)a. With the cast it compiles but fails at runtime if 'a' doesn't actually reference a B object (ClassCastException). Without cast, it won't compile.

Multiple choice technology programming languages
  1. A finalizer may NOT be invoked explicitly.

  2. The finalize method declared in class Object takes no action

  3. super.finalize() is called implicitly by any overriding finalize method

  4. The finalize method for a given object will be called no more than once by the garbage collector

  5. The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable

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

B is true because Object's finalize() is empty by default. D is true - GC guarantees finalize is called at most once per object. A is false - you CAN call finalize explicitly. C is false - super.finalize() must be called explicitly. E is false - finalization order is NOT guaranteed.

Multiple choice technology platforms and products
  1. Parent Class only

  2. Parent class and all its child classes

  3. Parent class and all its child classes unless explicitly overridden by another access rule

  4. None of the above

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

When an access role is specified at a parent class in Pega, it applies to that parent class AND all its child classes by default. However, if a child class has an explicit access rule that overrides the inherited role, the override takes precedence for that child class. This is inheritance with override capability.

Multiple choice technology platforms and products
  1. Same ClassGroup

  2. Same AccessGroup

  3. Same WorkPool

  4. None of the above

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

Cover and Covered objects in PEGA must belong to the same ClassGroup to maintain proper object relationships. The Cover-Covered relationship links related work objects within the same class group hierarchy, allowing parent-child associations. AccessGroup and WorkPool control different aspects (security and work assignment) and don't determine cover relationships.

Multiple choice technology platforms and products
  1. px

  2. py

  3. A and B

  4. pz

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

In PEGA, pz properties are system-protected read-only properties that cannot be modified by users or developers, ensuring system integrity. px and py properties can be modified under appropriate circumstances. The pz prefix specifically denotes protected system properties.

Multiple choice technology platforms and products
  1. Covered work objects inherit from Cover-Object- class

  2. Ordinary work objects inherit from the Work-Object- class

  3. Folders may contain only one covered work object

  4. Folders may be a work object

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

Ordinary work objects in PEGA inherit from the Work-Object- base class, which provides standard work object functionality. Covered work objects inherit from Work-Cover- class, not Cover-Object-. Folders can contain multiple covered objects, and folders themselves are organizational structures, not work objects.

Multiple choice technology platforms and products
  1. Pattern Inheritance

  2. Direct Inheritance

  3. Both

  4. None of the above

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

When creating a class in Pega, Direct Inheritance is mandatory - every class must have a parent class specified through direct inheritance. Pattern Inheritance is optional and provides an additional inheritance mechanism based on naming patterns. A class cannot exist without specifying its direct parent.

Multiple choice technology programming languages
  1. True

  2. False

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

Abstract classes cannot be instantiated directly because they contain at least one pure virtual function with no implementation. You can only create objects of concrete derived classes that implement all the pure virtual functions. The abstract class serves as a template for inheritance.

Multiple choice technology programming languages
  1. True

  2. False

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

Virtual functions in parent classes do NOT need to be redefined in all child classes. A child class can inherit the parent's implementation if it doesn't need custom behavior. The override is optional - it's only required if the child class needs specific behavior.

Multiple choice technology programming languages
  1. True

  2. False

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

In object-oriented theory and most language implementations, every class is considered a trivial subclass of itself. The "is-a" relationship is reflexive - a class is itself. This is mathematically consistent with inheritance hierarchies and type systems.

Multiple choice technology programming languages
  1. public constructor

  2. static constructor

  3. both

  4. I don't know.

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

Static constructors are invoked first when a class is initialized, before any instance constructor. They run once per type (not per object) to initialize static class members. The public constructor runs after the static constructor completes.