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
-
Picklist values change at runtime
-
Can be bounded or unbounded
-
Derive their values from LOV
-
Based on Picklist Generic Business Component
A
Correct answer
Explanation
The statement 'Picklist values change at runtime' is NOT true for static picklists - static picklists have fixed values that are defined at design time and do not change during application execution. This is what distinguishes them from dynamic picklists. Options B, C, and D are true characteristics of static picklists (they can be bounded/unbounded, derive from List of Values, and are based on Picklist Generic Business Component).
-
Is public
-
Extends Throwable
-
Implements Throwable
-
Is serializable
-
java.object
-
java.io
-
java.lang
-
java.applet
C
Correct answer
Explanation
Java automatically imports java.lang, which contains fundamental classes like String, Object, System, Math, and wrapper classes. All other packages (java.io, java.util, etc.) must be explicitly imported.
-
No difference, both are the same
-
An Object maynot have a class definition, but an instance must have a class definition
-
An Object must have a class definition, but an instance may not have a class definition
-
Object and Instance should have different class definitions. It can not be the same.
B
Correct answer
Explanation
In OOP terminology, 'object' is a broader concept - anything with identity, state, and behavior (including anonymous or prototype-based objects). 'Instance' specifically means an object created from a class definition using instantiation. An object may not have a formal class (as in prototype-based languages), but an instance must originate from a class.
-
Interfaces of the same package and other packages
-
Classes of the same package
-
Classes of the same package and other packages
-
Interfaces of the same package
B,D
Correct answer
Explanation
Protected members are accessible within the same package (to both classes and interfaces) and to subclasses in other packages via inheritance. Option C is wrong because it suggests same-class access isn't required.
A
Correct answer
Explanation
QuickTest Professional organizes test objects into classes based on their type and behavior (e.g., Window, WebEdit, Button). This object-oriented classification allows QTP to identify and interact with similar objects consistently across different applications. The class hierarchy is fundamental to QTP's object recognition model.
-
Class
-
Object properties
-
Object values
-
Run time objects
B
Correct answer
Explanation
In QuickTest Professional, the identifying characteristics of an object are called properties. These include attributes like name, class, value, and various other properties that help QTP uniquely identify and interact with the object during test execution. Properties distinguish one object from another in the application.
B
Correct answer
Explanation
Virtual constructors are impossible in C++ because constructing an object requires knowing its exact type at compile-time for memory allocation. Virtual dispatch works through vtables on already-constructed objects, but construction must happen before the object (and vtable) exists. Therefore, constructors cannot be virtual.
-
There is none; they both work as expected
-
They both do nothing.
-
The first will not invoke all myObj destructors
-
It would'nt delete all the memory allocated to the objects
C
Correct answer
Explanation
The delete[] operator is required for arrays because it invokes the destructor for every element in the array. Using plain delete only invokes the destructor for the first element (myObj) and not the remaining 99 objects, causing resource leaks. The pairing must be new[] with delete[] and new with delete.
-
Classes in class diagrams may be grouped into packages in order to illustrate the overall organization of a model
-
In object diagrams, names of instances are in italics or all-caps
-
If package B depends on package A, then any change in A will require a change in B
-
Object diagrams and class diagrams are completely interchangeable
A
Correct answer
Explanation
In UML class diagrams, classes can be grouped into packages to organize the model. Object diagram names are underlined (not italicized), package dependencies do not always force changes, and class/object diagrams are not fully interchangeable.
-
methods in the associated classes
-
subclasses needed to accomplish the same functionality
-
case statements and conditionals
-
coupling between classes in the system
C
Correct answer
Explanation
Polymorphism's key advantage is replacing conditional logic (case/switch statements and if-else chains) with dynamic dispatch through virtual functions. Instead of checking type and executing corresponding code, polymorphism lets each subclass implement its own behavior, invoked through a common interface. This reduces conditional complexity.
-
Multiple Inheritance and Overloading
-
Operator Overloading and Overriding
-
Multiple Inheritance and Operator Overloading
-
Pointers and Single Inheritance
C
Correct answer
Explanation
Java does not support multiple inheritance of classes (to avoid the diamond problem) nor does it support user-defined operator overloading. Therefore, this pair is not supported in Java.
B
Correct answer
Explanation
In Java, Map is a separate interface from Collection. Map does NOT extend Collection - they are distinct hierarchies. Collection is for groups of objects, Map is for key-value pairs.
-
is final
-
is public
-
is serializable
-
has a constructor which takes a StingBuffer Object as an Argument