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
-
The use of This; local to a function is illegal
-
Access modifiers can not be applied to local variables
-
All classes must be declared public
-
None of these
B
Correct answer
Explanation
In Java, local variables (declared inside methods) cannot have access modifiers like private, public, protected, or static. Access modifiers can only be applied to class-level members (fields, methods, classes). The statement 'private int x = 7;' inside a method will cause a compiler error because local variables cannot be declared private.
A
Correct answer
Explanation
In Java, a class can be declared abstract even without abstract methods. This prevents instantiation and is commonly used when a class provides partial implementation or when future subclasses are expected to add abstract methods. The abstract keyword signals intent to extend rather than use directly.
-
Only A
-
Only B
-
None of these
-
Both A & B
D
Correct answer
Explanation
In Java, both static initialization blocks and static nested classes are valid. Static initialization blocks run once when the class loads, useful for complex static initialization. Static nested classes are associated with the outer class rather than an instance, independent of outer class instances.
-
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
A,B,C
Correct answer
Explanation
Byte, Integer, and Short are wrapper classes that wrap primitive types byte, int, and short respectively. String is not a wrapper class; it's a reference type, not a wrapper for a primitive.
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.