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
-
Case 1 will compile and execute
-
Case 2 will compile and execute
-
Case 2 will compile but fail at runtime
-
Both the Cases wont compile
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.
-
A finalizer may NOT be invoked explicitly.
-
The finalize method declared in class Object takes no action
-
super.finalize() is called implicitly by any overriding finalize method
-
The finalize method for a given object will be called no more than once by the garbage collector
-
The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable
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.
-
Parent Class only
-
Parent class and all its child classes
-
Parent class and all its child classes unless explicitly overridden by another access rule
-
None of the above
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.
-
Mico-Finance
-
Finance-
-
Mico-Finance-
-
All of the above
A
Correct answer
Explanation
In Pega, pattern inheritance searches for parent classes by truncating segments separated by dashes. For the class MICO-Finance-, removing the trailing dash and the last segment yields MICO-Finance (or case-normalized Mico-Finance) as its pattern parent.
-
Same ClassGroup
-
Same AccessGroup
-
Same WorkPool
-
None of the above
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.
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.
-
Covered work objects inherit from Cover-Object- class
-
Ordinary work objects inherit from the Work-Object- class
-
Folders may contain only one covered work object
-
Folders may be a work object
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.
-
Pattern Inheritance
-
Direct Inheritance
-
Both
-
None of the above
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.
A,B
Correct answer
Explanation
Object and Math are fundamental classes in java.lang package. Object is the root class of all Java classes, and Math provides mathematical functions. Random is in java.util, and Stack is in java.util, not java.lang.
-
Byte
-
Integer
-
Short
-
String
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.
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.
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.
A
Correct answer
Explanation
this() is used in constructors to call another constructor of the same class (constructor chaining). It must be the first line in the constructor. This allows code reuse between overloaded constructors and avoids duplicating initialization logic.
-
public constructor
-
static constructor
-
both
-
I don't know.
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.