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
-
MyOuter.MyInner m = new MyOuter.MyInner();
-
MyOuter.MyInner mi = new MyInner();
-
MyOuter m = new MyOuter(); MyOuter.MyInner mi = m.new MyOuter.MyInner();
-
MyInner mi = new MyOuter.MyInner();
A
Correct answer
Explanation
For a static nested class, you use the fully qualified name with both outer and inner class names: 'new MyOuter.MyInner()'. Option B is missing 'MyOuter.' prefix. Option C incorrectly uses 'm.new' syntax (used for non-static inner classes). Option D is missing 'MyOuter.' prefix.
-
Unix command line interface
-
System dll
-
APT_dump
-
APT_Operator
D
Correct answer
Explanation
OSH (Orchestrate Shell) operators in DataStage are instances of C++ classes that inherit from the APT_Operator base class. This base class provides the framework for all operator functionality. APT_dump is a debugging tool. The OSH operators are not related to Unix CLI or system DLLs.
-
Directed Inheritance
-
Pattern Inheritance
-
Class Inheritance
-
Genetic Inheritance
B
Correct answer
Explanation
In PegaRULES Process Commander, pattern inheritance relies on alphabetical class naming where classes inherit from parent classes that match their name pattern. The Class Explorer's alphabetical view reveals this pattern inheritance structure. Direct inheritance follows explicit parent-child relationships instead.
B
Correct answer
Explanation
Object Identification is a mechanism for uniquely identifying objects based on their properties during test recording and playback. It is not designed to retrieve runtime property values - that purpose is served by specific methods like GetROProperty. Object Identification focuses on property-based object recognition, not runtime value extraction.
-
System creates private ruleset automaticaly when needed
-
instance of the Rule-Ruleset-Name class exists for a private RuleSet
-
name of this RuleSet is the same as their Operator ID
-
None
B
Correct answer
Explanation
A private ruleset (used for personal checkouts) is automatically managed by the system. Crucially, no actual Rule-Ruleset-Name instance is created in the database for a private ruleset, making the statement false and therefore the correct answer.
-
static
-
non-static
-
special-mixed type
-
not-defined
D
Correct answer
Explanation
Constructors in Java are not classified as static or non-static methods. They are a special type of block that initializes objects and have no explicit type-access modifier classification. While they behave like instance methods (they run on object creation), they are not technically methods and don't fit into the static/non-static binary.
-
Data Shadowing
-
Data Over-riding
-
Data Obscuring
-
None of the Above
D
Correct answer
Explanation
In Java, declaring a field in a subclass with the same name as an inherited field in the superclass is called field hiding (or variable hiding). Since field hiding is not listed among the options, 'None of the Above' is correct, as overriding only applies to methods.
B
Correct answer
Explanation
Anonymous inner classes in Java cannot have explicitly declared constructors. The compiler generates a default constructor, but developers cannot write constructors for anonymous classes. Only regular inner classes can have constructors.
B
Correct answer
Explanation
Local inner classes can access local variables from the enclosing method, but only if those variables are final or effectively final (not reassigned). This restriction ensures data consistency since the local variable might outlive the method's scope.
B
Correct answer
Explanation
Interface data members are always implicitly public, static, and final. They must be static constants, not instance variables. Non-static data members would require instantiation, which contradicts the purpose of interfaces.
B
Correct answer
Explanation
Top-level classes in Java cannot be declared static. However, nested classes (inner classes) inside another class can be declared as static. Static nested classes are different from inner classes - they don't have access to instance members of the enclosing class.
B
Correct answer
Explanation
Static inner classes (nested static classes) behave like regular classes - their members are NOT static by default. They can have both instance and static members, just like any other Java class. The 'static' keyword on the class only means it doesn't require an instance of the enclosing class.
B
Correct answer
Explanation
Anonymous inner classes can be created within interfaces in specific contexts. While interfaces cannot have instance initializers, anonymous classes can be defined inside static contexts like static field initialization or static blocks within the interface. This is a valid though rarely used Java feature.