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
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).
-
RuntimeException
-
Error
-
VirtualMachineError
-
IllegalAccessException
B
Correct answer
Explanation
In Java, the AssertionError class extends Error, which in turn extends Throwable. The 'is-a' relationship refers to inheritance. AssertionError is used when an assertion fails, and Error is the superclass for serious system-level errors that applications should not try to catch. Option B is correct.
-
Both classes extend Throwable.
-
The Error class is final and the Exception class is not.
-
The Exception class is final and the Error is not.
-
Both classes implement Throwable.
A
Correct answer
Explanation
Both Error and Exception classes extend Throwable in the Java exception hierarchy. Throwable is the superclass of all errors and exceptions in Java. Neither Error nor Exception is final - both have subclasses. They extend (inherit from) Throwable, not implement it as an interface. Option A is correct.
-
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.
-
The id attribute must be defined for <jsp:usebean>.
-
The scope attribute must be defined for <jsp:usebean>.
-
The class attribute must be defined for <jsp:usebean>.
-
The <jsp:usebean> must include either type or class attribute or both.
A,D
Correct answer
Explanation
For , the id attribute is mandatory as it provides the variable name for accessing the bean. The scope attribute is optional with 'page' as default. Either type or class attribute (or both) must be present, but not both class and beanName together.
-
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.
-
It is possible for a single class to implement multiple interfaces
-
It is possible for a class to inherit from multiple classes
-
It is possible for a class to inherit from a Sealed class
-
All of above
A
Correct answer
Explanation
A class can implement multiple interfaces because interfaces only define contracts without implementation. Multiple inheritance from classes is not allowed in C# due to complexity and ambiguity issues (the diamond problem). Sealed classes explicitly prevent inheritance by design.