Computer Knowledge
Object-Oriented Programming
2,239 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
A
Correct answer
Explanation
Abstract classes in Java CAN have constructors. While they cannot be instantiated directly, their constructors are called when a subclass is instantiated using super(). This allows initialization of inherited fields and setup logic.
-
a class implements one or more interfaces
-
a class extends one or more interfaces
-
an interface extends one of more interfaces
-
Serializable is a marker Interface
B
Correct answer
Explanation
Classes IMPLEMENT interfaces, not extend them. Option B claims classes extend interfaces, which is false - you use 'implements' keyword for interfaces. Classes extend other classes, and interfaces extend other interfaces.
-
By reference
-
By object copy
-
By producing a serialized copy
-
None
B,C
Correct answer
Explanation
When passing objects to remote methods in Java RMI, objects are passed by serialized copy (deep copy). This serialization process creates an object copy on the receiving side. By reference is not possible across JVM boundaries.
A
Correct answer
Explanation
Java allows marker interfaces - interfaces with no methods. They are used to mark classes for special treatment by the JVM or compiler (e.g., Serializable, Cloneable). An empty interface declaration is syntactically valid and serves this purpose.
A
Correct answer
Explanation
The isomorphic namespace defines four default data operations: Fetch (read), Add (create), Update (modify), and Remove (delete). 'Create' is not a standard operation - the correct term is 'Add'.
-
Abstract Class
-
Interface
-
Final Method
-
none of the above
B
Correct answer
Explanation
Java doesn't support multiple inheritance of classes to avoid the diamond problem and complexity. However, a class can implement multiple interfaces, which is the only way to achieve multiple inheritance in Java. Abstract classes follow single inheritance rules, and final methods prevent overriding entirely.
B
Correct answer
Explanation
Final methods in Java cannot be overridden. The final keyword specifically prevents a method from being modified or redefined by subclasses. This is used when you want to ensure a method's implementation remains consistent and unchanged throughout the inheritance hierarchy for security or design reasons.
-
class A,class B extends A,class C extends B
-
class A implements B,implements C
-
class A extends B,extends C
-
none of the above
A
Correct answer
Explanation
Multilevel inheritance occurs when a class is derived from another derived class. 'Class B extends A' and 'Class C extends B' forms a chain (A -> B -> C), which is the definition of multilevel inheritance.
-
one per method
-
one per object
-
one per class
-
one per package
C
Correct answer
Explanation
In Java, the 'static' keyword indicates that a member (field or method) belongs to the class itself rather than to individual instances (objects) of the class. There is only one copy of a static member shared by all instances.
-
public
-
private
-
default(no access modifier)
-
protected
C
Correct answer
Explanation
The default access modifier (no keyword used) restricts access to classes within the same package. 'Private' is class-only, 'Protected' includes subclasses in other packages, and 'Public' is accessible from everywhere.
-
Autounboxing
-
Autoboxing
-
polymorphism
-
encapsulation
B
Correct answer
Explanation
Autoboxing is Java's automatic conversion from primitive types (int, double, boolean) to their corresponding wrapper class objects (Integer, Double, Boolean). The reverse conversion (wrapper to primitive) is called unboxing. Polymorphism and encapsulation are unrelated OOP concepts.
-
A,C,B
-
C,B,A
-
A,B,C
-
none of the above
C
Correct answer
Explanation
In Java inheritance, when a subclass object is instantiated, the constructors are called in order from the top of the hierarchy down. Thus, the constructor for A (superclass) runs first, then B, then C (subclass).
-
String
-
Integer
-
Boolean
-
Character
A
Correct answer
Explanation
Wrapper classes in Java wrap primitive types (like Integer for int, Boolean for boolean, Character for char) to allow primitives to be used in contexts requiring objects. String, however, is not a wrapper class - it's an immutable class that represents a sequence of characters, not a wrapper for a primitive type. Option A is correct.
-
import java.awt.*;package Mypackage;class Myclass {}
-
package MyPackage;import java.awt.*;class MyClass{}
-
/This is a comment */package MyPackage;import java.awt.;class MyClass{}
-
class Myclass {};import java.awt.*;package Mypackage;
B,C
Correct answer
Explanation
Java requires package declaration (if present) to come before import statements. Comments can appear before the package. Option A has the wrong order, D has package after class, while B and C follow the correct structure.
-
Only 2
-
Both 1 and 3
-
4
-
Both 2 and 4
B
Correct answer
Explanation
System.Collections.ArrayList is non-generic and CAN store multiple data types (statement 2 is true, so 1 is false). System.Collections.Generic.List is generic and enforces a single type (statement 4 is true, so 3 is false). The question asks which statements are FALSE - statements 1 and 3 are both false.