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
A
Correct answer
Explanation
Constructors can be overloaded by defining multiple constructors with different parameter lists, allowing objects to be initialized in different ways.
B
Correct answer
Explanation
Abstract classes cannot be instantiated directly. They serve as base classes and must be inherited by concrete classes that implement all pure virtual functions.
-
Public
-
Protected
-
Private
-
Default
C
Correct answer
Explanation
To solve this question, the user needs to know the concept of access modifiers in object-oriented programming and their default level assigned to the members of a class.
Now, let's go through each option and explain why it is right or wrong:
A. Public: This option is incorrect. Public access modifier allows members of a class to be accessible from anywhere in the program. However, it is not the default access level assigned to members of a class.
B. Protected: This option is incorrect. Protected access modifier allows the members of a class to be accessible within the class and its subclasses. However, it is not the default access level assigned to members of a class.
C. Private: This option is correct. Private access modifier allows the members of a class to be accessible within the class only. It is the default access level assigned to the members of a class if no other access modifier is explicitly specified.
D. Default: This option is incorrect. Default access modifier allows the members of a class to be accessible within the package only. It is not the default access level assigned to the members of a class.
The Answer is: C
-
Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding
-
Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called a overloaded fucntion.
-
Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding
-
Redefining a function in a friend class is called function overloading while Redefining a function in a derived class is called as overridden fucnion.
C
Correct answer
Explanation
Overloading occurs at compile-time when functions with the same name have different parameters. Overriding happens at runtime when a derived class provides a new implementation for a base class virtual function.
-
Template class
-
Function template
-
Class template
-
Both a and c
B
Correct answer
Explanation
A function template in C++ defines a general set of operations that can be applied to various types of data passed as parameters. While a class template defines a family of classes, a function template specifically represents operations (functions). Therefore, 'Both a and c' is incorrect.
A
Correct answer
Explanation
C++ does not support virtual constructors. Object construction requires knowing the exact type at compile-time. Virtual destructors exist and are important for proper cleanup of derived class objects through base pointers.
-
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
In role-based access control systems like Pega, access roles defined at a parent class level automatically inherit down to all child classes. This inheritance persists unless explicitly overridden by a more specific access rule defined at the child class level. Other options miss this conditional override.
D
Correct answer
Explanation
In PRPC, pz prefix properties (Pega-provided protected) are read-only and cannot be modified by developers or users. px properties are public and can be modified, while py properties are your custom properties that you can modify. The pz layer is Pega's protected code that shouldn't be altered.
-
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 inherit from the Work-Object- base class in PRPC. Covered work objects inherit from Work-Cover- class, not Cover-Object-. Folders can contain multiple covered work objects, and folders themselves are work objects (Work-Folder- class), so options C and D are false.
-
Same ClassGroup
-
Same AccessGroup
-
Same WorkPool
-
None of the above
A
Correct answer
Explanation
In Pega's covering feature, both the Cover (parent) and Covered (child) work objects must belong to the same ClassGroup. This requirement ensures proper inheritance and processing rules apply consistently. AccessGroup and WorkPool control different aspects of security and work routing.
-
Pattern Inheritance
-
Direct Inheritance
-
Both
-
None of the above
B
Correct answer
Explanation
Direct Inheritance is mandatory when creating a class - every class must specify its direct parent class using direct inheritance. Pattern Inheritance is optional and provides additional fallback mechanisms for rule resolution beyond the direct inheritance chain.
-
Mico-Finance
-
Finance-
-
Mico-Finance-
-
All of the above
A
Correct answer
Explanation
Pattern inheritance works by removing the trailing dash segment and moving up the hierarchy. For MICO-Finance-, removing the trailing dash gives Mico-Finance as the pattern inheritance parent. This is how Pega's pattern inheritance algorithm navigates the class structure.
-
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
In Pega's access control inheritance model, when an access role is specified at a parent class level, it automatically applies to that parent class AND all its child classes throughout the class hierarchy. This cascading inheritance ensures consistent permissions across related classes. However, if a child class has an explicit access rule that overrides the inherited role, the child's specific rule takes precedence for that class.
D
Correct answer
Explanation
Pega property types starting with pz are protected system properties that cannot be modified. Properties starting with px are standard Pega properties that can be modified, and py properties are also editable. The pz prefix designation is specifically reserved for locked, read-only system properties that maintain platform integrity.
-
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
In Pega's class hierarchy, ordinary work objects inherit from the Work-Object- base class, making option B true. Covered work objects inherit from Work-Cover- class, not Cover-Object-. Folders can contain multiple covered work objects, and folders themselves are typically organizing structures rather than work objects.