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
  1. A super class is a sub set of a sub class

  2. class ClassTwo extends ClassOne means ClassOne is a subclass

  3. class ClassTwo extends ClassOne means ClassTow is a super class

  4. the class Class is the super class of all other classes in Java.

Reveal answer Fill a bubble to check yourself
A Correct answer
Multiple choice
  1. HashTable is a sub class of Dictionary

  2. ArrayList is a sub class of Vector

  3. LinkedList is a subclass of ArrayList

  4. Vector is a subclass of Stack

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

Hashtable extends Dictionary in Java's legacy collections framework. Note: Dictionary is deprecated and Hashtable should be Hashtable (capital T), but the inheritance relationship is correct.

Multiple choice
  1. LinkedList extends List

  2. AbstractSet extends Set

  3. HashSet extends AbstractSet

  4. WeakHashMap extends HashMap

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

HashSet extends AbstractSet in Java's collections framework. LinkedList implements List (List is an interface), AbstractSet implements Set, and WeakHashMap extends AbstractMap.

Multiple choice
  1. protected

  2. extends Throwable

  3. implements Throwable

  4. serializable

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

Exception extends Throwable in Java's exception hierarchy. Throwable is the base class, with Exception and Error as its two main subclasses. Checked and unchecked exceptions extend from Exception.

Multiple choice
  1. An instance of a class is an object

  2. Objects can access both static and instance data

  3. Object is the super class of all other classes

  4. Objects do not permit encapsulation

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

Objects are the fundamental units in OOP that DO permit encapsulation - they bundle data and methods together while restricting access to internal details. Option A is true because objects are instances of classes. Option B is true because objects can access both static (class-level) and instance data. Option C is true because in Java, Object is indeed the root class from which all other classes inherit.

Multiple choice
  1. Only Static methods of the same class

  2. Only instances of the same class

  3. Only methods those defined in the same class

  4. Only classes available in the same package.

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

In Java, private members are accessible only within the same class - whether from static methods, instance methods, or other instances of that same class. Methods defined in the same class can access private attributes regardless of whether they are static or instance methods. Other classes in the same package cannot access private members.

Multiple choice
  1. Method Invocating

  2. Method Overriding

  3. Method Labeling

  4. Method Overloading

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

Method overloading allows a class to have multiple methods with the same name but different parameter lists (different number of parameters, different types, or both). This is compile-time polymorphism. Method overriding is when a subclass provides a specific implementation of a method already defined in its superclass (same name and parameters).

Multiple choice
  1. Object

  2. Class

  3. Method

  4. Real data types

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

A class is a blueprint or template that defines the structure and behavior of objects. It specifies what attributes (variables) and methods will be common to all objects created from it. Objects are the actual instances created from this blueprint. Methods define behavior, and real data types are primitive types, not blueprints.

Multiple choice
  1. An object with only primitive attributes

  2. An instance of a class which has only static methods

  3. An instance which has other objects

  4. None of the above

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

An aggregate object is an object that contains or references other objects as part of its state. This represents a 'has-a' relationship (composition/aggregation). For example, a Car object might contain Engine, Wheel, and Seat objects. This is different from an object having only primitive attributes or only static methods.

Multiple choice
  1. Binary File

  2. Image File

  3. Both File and Binary Files

  4. None of the above

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

This is polymorphism through dynamic method dispatch. When a superclass reference points to a subclass object (File reference to ImageFile), and a method is called, Java uses the actual object's type (not the reference type) to determine which implementation to execute. Since the reference points to an ImageFile object, the ImageFile's toFile() method will be called.

Multiple choice
  1. Object

  2. Window

  3. Panel

  4. Component

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

In Java AWT, the Applet class directly extends Panel, making Panel its immediate superclass. The class hierarchy is: Applet -> Panel -> Container -> Component -> Object.

Multiple choice
  1. Font class

  2. Regular class

  3. FontMetrics class

  4. Graphics class

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

FontMetrics is a specialized class that provides font measurement data like ascent (distance from baseline to top of characters) and descent (distance from baseline to bottom). The Font class itself represents the font but doesn't provide these detailed metrics.

Multiple choice
  1. 9

  2. 7

  3. 8

  4. 6

  5. 5

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

This is the correct answer. there are 7 subclasses of InputStream class.hese are :-1.) FileInputStream :- for reading bytes from a file.2.) ObjectInputStream :- for readin objects and primitive data types from input stream.3.) SequenceInputStream :- for readin from a sequence of streams.4.) ByteArrayInputStream :- for Stream that reads a byte array.5.) pipedInputStream :- for reading from a piped stream.6.) FilterInputStream :- for filtering input from Existing Stream.7.) StringBufferInputStream:- for readin from a string.These are the 7 subclasses.So this is correct answer.