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

Multiple choice technology programming languages
  1. Single Inheritence

  2. Double Inheritence

  3. Multiple Inheritence

  4. Class Inheritence

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Java supports single class inheritance, meaning a class can only extend one superclass directly. Java does not support multiple inheritance of classes (only multiple inheritance of interfaces through implementation). Double inheritance is not a standard term, and class inheritance is a general concept rather than a type.

Multiple choice technology programming languages
  1. the new method should return int

  2. the new method can return any type of values

  3. the argument list of new method should exactly match that of overriden method

  4. the return type of new method should exactly match that of overriden method

Reveal answer Fill a bubble to check yourself
C,D Correct answer
Explanation

When overriding a method in Java, the signature (parameter list) must match exactly, and the return type must be the same or a covariant subtype (not changed arbitrarily). Options A and B are incorrect.

Multiple choice technology programming languages
  1. abstract double area() { }

  2. abstract double area()

  3. abstract double area();

  4. abstract double area(); { }

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

An abstract method in Java is declared with the abstract keyword and has no method body (just a semicolon). Option C shows correct syntax. Option A has a body (not abstract), B is incomplete, D has invalid syntax.

Multiple choice technology programming languages
  1. Thread

  2. Runnable

  3. Implements

  4. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, to make a class runnable as a thread, you implement the Runnable interface which contains the run() method. This is the preferred way over extending the Thread class because it allows your class to extend another class if needed. Option A is incorrect because Thread is a class, not an interface you implement.

Multiple choice technology programming languages
  1. Interface and Class

  2. Class and Interface

  3. interface and interface

  4. class and class

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Map is an interface in Java that defines the contract for key-value mappings, while HashMap is a concrete class implementing that interface. The question asks for HashMap first, then Map.

Multiple choice technology programming languages
  1. Method overriding

  2. Method overloading

  3. Method overwriting

  4. None of the above

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

Multiple choice technology programming languages
  1. constructor

  2. Destructor

  3. Class

  4. method

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

Multiple choice technology programming languages
  1. Wrapper Classes

  2. Super Classes

  3. Sub Classes

  4. None of the above

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

Multiple choice technology programming languages
  1. The Void class extends the Class class.

  2. The Float class extends the Double class.

  3. The System class extends the Runtime class.

  4. The Integer class extends the Number class.

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

Multiple choice technology programming languages
  1. initialize instance variables

  2. destroy variables

  3. both (a) and (b)

  4. None of the above

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