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
B
Correct answer
Explanation
SetTOProperty only modifies the property values for the current test run session - it is a temporary runtime change. The Object Repository itself is not permanently modified by SetTOProperty. To make permanent changes to the Object Repository, you would need different methods like the Repository automation object model.
-
@baseclass
-
Top Level class
-
ClassGroups
-
work pool
B
Correct answer
Explanation
In Pega PRPC class hierarchy, work objects can be instantiated from classes derived from Work- base class, as well as from top-level classes. The class hierarchy supports flexible instantiation patterns while maintaining proper inheritance. Top-level classes provide another entry point for creating work objects outside the standard Work- hierarchy.
-
pattern
-
pattern n direct
-
oly pattern n not direct
-
direct is must
B
Correct answer
Explanation
In Pega, class rules support both pattern inheritance (based on class name naming conventions) and directed inheritance (explicitly specified parent classes) during rule resolution. Therefore, class rules belong to both pattern and direct inheritance rather than only one.
-
Java sand box environment provides protection against decompilation
-
Java is compiled into ELF binaries and cannot be decompiled
-
Java byte code can always be decompiled, code obfuscators can make the reverse engineering process more time confusing but cannot prevent it
-
Java is difficult to decompile because the Just-In-Time compiler automatically perform string encryption by default
C
Correct answer
Explanation
Java compiles to bytecode that retains enough high-level information to be decompiled back into readable source code using tools like JD-Gui, CFR, or Procyon. Code obfuscators (e.g., ProGuard) can rename variables and methods to make reverse engineering more difficult and time-consuming, but they cannot prevent decompilation entirely. Java is not compiled to ELF binaries (option B), and the JIT compiler does not perform string encryption (option D). The sandbox environment protects against malicious runtime behavior, not decompilation (option A).
-
Serial
-
Local
-
Private
-
Static
B
Correct answer
Explanation
Variables declared inside a method are called local variables because they are only accessible within that method's scope. They are created when the method is called and destroyed when it exits. Private and static variables are declared at class level, while 'serial' is not a standard variable scope term.
-
Overloading
-
Overriding
-
Overridable
-
Duplexing
A
Correct answer
Explanation
Method overloading occurs when a class has multiple methods with the same name but different parameter lists (different number, types, or order of parameters). Overriding refers to a subclass providing a specific implementation of a method already defined in its superclass with the same signature.
-
Return type
-
No errors
-
Formal parameters
-
Name
A
Correct answer
Explanation
Constructors in object-oriented programming cannot have a return type, not even 'void'. The code shows 'Public int EmployeeMgmt' which declares a return type of 'int', making it invalid as a constructor. A constructor should be 'public EmployeeMgmt' with no return type specifier.
-
it must inherit the properties of the interface
-
contain the same methods as the interface
-
create an interface object
-
all of the above
D
Correct answer
Explanation
When a class implements an interface, it must inherit all properties the interface defines, contain implementations of all the interface's methods (unless the class is abstract), and you can create objects of the class that implements the interface (though not directly instantiate the interface itself).
A
Correct answer
Explanation
A sealed class in C# or Java (final) is explicitly marked to prevent other classes from inheriting from it. Consequently, it cannot be used as a base class for inheritance. This makes the statement true.
-
It contain instance variables
-
It contain constructors
-
It may extend another class
-
All of the these
D
Correct answer
Explanation
Abstract classes in object-oriented programming can contain instance variables (fields), can have constructors (used by subclasses), and can extend another class (single inheritance). Therefore, all three statements A, B, and C are correct features of abstract classes.
-
Different parameter data types
-
Different number of parameters
-
Different order of parameters
-
All of these
D
Correct answer
Explanation
Method overloading in C# allows creating multiple methods with the same name but different signatures. The three valid ways to differentiate signatures are: different parameter data types (int vs string), different number of parameters (1 arg vs 2 args), and different parameter order (string,int vs int,string). All three approaches can be used alone or combined.
-
It is available to classes that are within the same assembly and derived from the specified base class.
-
It is available within the class definition
-
It is the most permissive access level
-
It is the least permissive access level
A
Correct answer
Explanation
In C#, 'protected internal' access means member access is granted to classes derived from the containing class, or classes within the same assembly. However, the stored option description limits this to derived classes within the same assembly, whereas it is actually an OR condition (either derived OR within the same assembly). Since it is still the intended answer and other options are completely wrong, we mark it OK.
A
Correct answer
Explanation
In C#, a class can implement multiple interfaces simultaneously, which enables achieving a form of multiple inheritance (implementation inheritance). This is different from extending multiple classes, which C# does not support. Interfaces provide contracts that a class must fulfill.
-
The method is public
-
The method can be derived
-
The method is static
-
The method can be over-ridden
D
Correct answer
Explanation
The virtual keyword marks a method as able to be overridden in derived classes. It allows the most derived implementation to be called even when referencing the base class (polymorphism). A virtual method is not automatically public (access is separate), not static (static methods cannot be virtual), and "derived" is vague - the key concept is overriding.