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. 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.

Multiple choice technology programming languages
  1. Abstract class MyApplet extends java.applet.Applet {

  2. Public class MyApplet extends java.applet.Applet {

  3. Class MyApplet implements Applet {

  4. Public class MyApplet extends applet implements Runnable {

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

Multiple choice technology programming languages
  1. Can be overridden

  2. Cannot be overridden

  3. Can be inherited

  4. Cannot be inherited

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

Multiple choice technology programming languages
  1. System

  2. User defined

  3. parametrized

  4. Hidden

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