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
Object diagrams show specific instances of classes with their actual attribute values at a given moment. While class diagrams define the structure and relationships, object diagrams require runtime state information and specific instance data that cannot be derived from class definitions alone. You need to know what objects actually exist and their current state to create an object diagram.
-
Interface
-
Class
-
Abstract Class
-
Filter
-
None
C
Correct answer
Explanation
GenericServlet is an abstract class in the Java Servlet API, not an interface or concrete class. It implements the Servlet interface and provides basic implementations for most methods, except service() which remains abstract. Subclasses must implement service().
-
Interface
-
Class
-
Abstract Class
-
All
-
None
C
Correct answer
Explanation
Abstract classes can have both abstract methods (without implementation) and concrete methods (with implementation). This allows partial implementation - some methods are implemented, others are left abstract for subclasses to implement. Interfaces require all methods to be implemented by the implementing class, and concrete classes must provide complete implementation.
-
Interface
-
Class
-
Abstract Class
-
Filter
-
None
C
Correct answer
Explanation
GenericServlet is an abstract class in Java Servlet API that implements the Servlet interface. It provides basic implementation of most Servlet methods except service(), which must be implemented by subclasses. HttpServlet extends GenericServlet to provide HTTP-specific functionality. GenericServlet is not an interface, not a concrete class, and not a Filter.
-
Interface
-
Class
-
Abstract Class
-
All
-
None
C
Correct answer
Explanation
Abstract classes are designed specifically to provide partial implementation - they can have both abstract methods (without implementation) and concrete methods (with implementation). Interfaces require all methods to be implemented (before Java 8) and regular classes must provide complete implementations. Only abstract classes allow the flexibility of implementing some methods while leaving others for subclasses to complete.
-
Can create instances of concrete classes
-
Must have patterns & direct inheritance
-
Must have direct inheritance and need not have pattern inheritance.
-
Need not have either pattern or direct inheritance
A,C
Correct answer
Explanation
Concrete classes in Pega are classes from which instances can be created (option A is correct). They must have direct inheritance (a parent class) but are not required to have pattern inheritance (option C is correct). Pattern inheritance is optional for concrete classes, so they need not have it (making C correct, not B). Option D is incorrect because they must have at least direct inheritance.
-
Work-
-
.@baseclass
-
Class group
-
None of the above
C
Correct answer
Explanation
In Pega, the Class Group (work pool) container is responsible for defining the key structure (typically pyID) and mapping instantiated work objects of its member classes to a single database table. 'Work-' and '.@baseclass' are base classes, not key definitions.
-
(a) Code-Pega-List
-
(b) Rule-Pega-Obj
-
(c) pxResults
-
(d) The same class as the returned instance
A
Correct answer
Explanation
The Obj-List method creates a top-level clipboard page with class Code-Pega-List. This class contains query results. Rule-Pega-Obj is for individual rule instances, pxResults is a property name within the list page, and the class is not the same as the returned instance class.
-
(a) Code-Pega-List
-
(b) Rule-Pega-Obj
-
(c) pxResults
-
(d) The same class as the returned instance
A
Correct answer
Explanation
Obj-List always creates a top-level clipboard page of class Code-Pega-List, which contains the results of the database query. The pxResults mentioned in option C is actually a property within that page, not the class itself. Code-Pega-List is Pega's standard class for list-type results.
-
List<string>
-
IEnumerable<string>
-
List<object>
-
IEnumerable<object>
B
Correct answer
Explanation
The Where() extension method on List returns IEnumerable, the deferred execution sequence interface. This is the standard LINQ return type for filtering operations. The actual runtime type is a nested iterator class, but the declared return type is IEnumerable. It is not List or the object variant.
B
Correct answer
Explanation
Static methods belong to the class itself, not to any specific instance. They can only access static variables (class variables) and cannot directly reference instance variables, which require an object instance to exist. This is a fundamental Java concept regarding method types and variable scope.
-
Two methods defined in that interface
-
Only certain methods in an interface
-
Any methods in a class
-
All methods defined in that interface
D
Correct answer
Explanation
When a class implements an interface, it enters a contract to provide concrete implementations for ALL methods declared in that interface. This is a fundamental Java principle - interfaces define what a class MUST do, and the implementing class provides the specific behavior for every method.
-
To avoid having to declare variables
-
To refer to a class without using prefixes
-
To avoid calling methods
-
To import the images you want to use
B
Correct answer
Explanation
Import statements allow you to reference classes by their simple names instead of using fully qualified names with package prefixes. This improves code readability and reduces verbosity - instead of writing 'java.util.ArrayList' repeatedly, you can import it once and use 'ArrayList' throughout your code.
B
Correct answer
Explanation
Wicket does NOT require objects referenced by CompoundPropertyModel to be Serializable. While serialization can be useful for clustering or session replication, it is not mandatory for basic CompoundPropertyModel functionality.
B
Correct answer
Explanation
Objects referenced by CompoundPropertyModel should ideally be Serializable to support session replication, clustering, and other scenarios where the session may be serialized. However, Wicket does not strictly enforce this for basic operation, so the answer is False - it's recommended but not required.