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

Multiple choice technology programming languages
  1. Abstract Class

  2. Interface

  3. Final Method

  4. none of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. class A,class B extends A,class C extends B

  2. class A implements B,implements C

  3. class A extends B,extends C

  4. none of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. one per method

  2. one per object

  3. one per class

  4. one per package

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Autounboxing

  2. Autoboxing

  3. polymorphism

  4. encapsulation

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. A,C,B

  2. C,B,A

  3. A,B,C

  4. none of the above

Reveal answer Fill a bubble to check yourself
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).

Multiple choice technology programming languages
  1. RuntimeException

  2. Error

  3. VirtualMachineError

  4. IllegalAccessException

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Both classes extend Throwable.

  2. The Error class is final and the Exception class is not.

  3. The Exception class is final and the Error is not.

  4. Both classes implement Throwable.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. String

  2. Integer

  3. Boolean

  4. Character

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. The id attribute must be defined for <jsp:usebean>.

  2. The scope attribute must be defined for <jsp:usebean>.

  3. The class attribute must be defined for <jsp:usebean>.

  4. The <jsp:usebean> must include either type or class attribute or both.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. import java.awt.*;package Mypackage;class Myclass {}

  2. package MyPackage;import java.awt.*;class MyClass{}

  3. /This is a comment */package MyPackage;import java.awt.;class MyClass{}

  4. class Myclass {};import java.awt.*;package Mypackage;

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Only 2

  2. Both 1 and 3

  3. 4

  4. Both 2 and 4

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. It is possible for a single class to implement multiple interfaces

  2. It is possible for a class to inherit from multiple classes

  3. It is possible for a class to inherit from a Sealed class

  4. All of above

Reveal answer Fill a bubble to check yourself
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.