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
-
Polymorphism
-
Inheritance
-
Encapsulation
-
Both a &b
A
Correct answer
Explanation
Polymorphism allows one interface to represent a general class of actions, where specific implementations can vary while the interface remains consistent. This is a core OOP principle enabling flexible, reusable code.
-
Method overriding
-
Method overloading
-
Method overwriting
-
None of the above
B
Correct answer
Explanation
Method overloading occurs when a class has multiple methods with the same name but different parameter lists (different number, type, or order of parameters). This allows the same method name to perform different actions based on input.
-
Method overriding
-
Method overloading
-
Method overwriting
-
None of the above
-
constructor
-
Destructor
-
Class
-
method
A
Correct answer
Explanation
The this() keyword is used to call another constructor in the same class, enabling constructor chaining. It must be the first statement in a constructor and helps avoid code duplication when multiple constructors share common initialization logic.
-
Inner Class
-
Sub class
-
Private Class
-
Both a &b
A
Correct answer
Explanation
Classes defined within other classes, including nested classes or local classes inside methods, are collectively referred to as inner classes. Subclasses inherit from parent classes, and private classes refer to access visibility.
-
One
-
Two
-
Three
-
None of the above
D
Correct answer
Explanation
The Cloneable interface is a marker interface that contains NO methods. It indicates that a class permits cloning - the actual clone() method is inherited from Object class. Marker interfaces exist for type-safety and compiler checks only.
-
Wrapper Classes
-
Super Classes
-
Sub Classes
-
None of the above
A
Correct answer
Explanation
Wrapper classes in Java (Integer, Double, Character, Boolean, etc.) encapsulate primitive data types within objects. This allows primitives to be used in contexts requiring objects, such as collections. Super classes and sub classes refer to inheritance relationships, not primitive wrapping.
-
The Void class extends the Class class.
-
The Float class extends the Double class.
-
The System class extends the Runtime class.
-
The Integer class extends the Number class.
D
Correct answer
Explanation
The Integer wrapper class extends the abstract Number class, which is part of Java's type hierarchy for numeric types. Void does not extend Class (Void is final). Float extends Number, not Double. System does not extend Runtime. Only the Integer-Number relationship is correct.
-
initialize instance variables
-
destroy variables
-
both (a) and (b)
-
None of the above
A
Correct answer
Explanation
Constructors are special methods in Java used to initialize the instance variables of an object when it is created. Destructors or garbage collection handle destroying variables, so option b is incorrect.
-
Abstract class MyApplet extends java.applet.Applet {
-
Public class MyApplet extends java.applet.Applet {
-
Class MyApplet implements Applet {
-
Public class MyApplet extends applet implements Runnable {
B
Correct answer
Explanation
A valid applet declaration must be a public class that extends java.applet.Applet (or javax.swing.JApplet for Swing). Option B correctly declares 'Public class MyApplet extends java.applet.Applet' (assuming 'Public' is a typo for 'public'). Option A incorrectly uses 'abstract', option C incorrectly uses 'implements', and option D incorrectly combines 'extends applet' (should be 'extends java.applet.Applet') with 'implements Runnable'.
-
abstract double area() { }
-
abstract double area()
-
abstract double area();
-
abstract double area(); { }
C
Correct answer
Explanation
An abstract method declares a method signature without implementation. It ends with a semicolon and has no body (no braces). Option C shows the correct syntax with semicolon and no braces.
-
Can be overridden
-
Cannot be overridden
-
Can be inherited
-
Cannot be inherited
B
Correct answer
Explanation
A final method cannot be overridden in subclasses. This enforces that the implementation remains unchanged throughout the inheritance hierarchy. However, final methods can still be inherited and called by subclasses.
-
%SerialObject
-
%RegisteredObject
-
%Persistent
-
%Transient
A
Correct answer
Explanation
In Caché ObjectScript, %SerialObject is the base class for serial objects - objects that can be serialized but don't have independent storage. This is the correct inheritance for creating a serial class.
-
System
-
User defined
-
parametrized
-
Hidden
A
Correct answer
Explanation
In Caché ObjectScript, %classes refer to system classes - classes starting with % are provided by the system. User-defined classes don't use the % prefix. The claimed answer A (System) is correct.