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

  2. List

  3. Map

  4. Vector

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

The Set interface is designed for collections that contain no duplicate elements. Implementations like HashSet enforce uniqueness without imposing any ordering requirement. Lists allow duplicate elements, Maps store key-value pairs, and Vector (a legacy List implementation) also permits duplicates.

Multiple choice technology web technology
  1. Interface in Java

  2. pointer in C or C++

  3. function pointer in C or C++

  4. Interface in .NET

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

Delegates in .NET are type-safe object references that encapsulate a method. This concept is conceptually identical to function pointers in C or C++.

Multiple choice technology web technology
  1. private

  2. protected

  3. protected internal

  4. It is not possible to do it

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

protected internal combines both access modifiers: accessible within the current assembly (internal) AND to derived classes in other assemblies (protected). private is class-only, protected excludes current assembly, and option D is incorrect.

Multiple choice technology programming languages
  1. True

  2. False

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

Serializable is a marker interface - it has NO methods. The JVM checks for this interface at runtime to enable serialization, but there's no requirement to override any methods. The statement claiming it has two methods that must be overridden is false.

Multiple choice technology programming languages
  1. A method is an implementation of an abstraction

  2. A method is an attribute defining the property of a particular abstraction

  3. A method is an operation defining the behavior for a particular abstraction

  4. A method is a blueprint for making operations

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

In object-oriented programming, a method is an operation that defines the behavior for a particular abstraction. It encapsulates the actions or behaviors that objects of a class can perform. Option A is incorrect because methods define behavior, not implementation of abstraction. Option B is incorrect because attributes (not methods) define properties.

Multiple choice technology programming languages
  1. They pass messages by modifying each other's fields

  2. They pass messages by calling each other's instance methods

  3. They pass messages by modifying the static variables of each other's classes

  4. They pass messages by calling static methods of each other's classes

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

In object-oriented programming, objects interact and communicate by invoking (calling) each other's instance methods. Modifying fields directly violates encapsulation, and static methods belong to classes rather than individual object instances.

Multiple choice technology programming languages
  1. True

  2. False

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

Unlike TreeSet, a HashSet does not sort its elements and does not compare them using Comparable. It uses hashCode() and equals(), which are defined on all objects. Therefore, adding a String and an Integer to a HashSet will not cause a ClassCastException.

Multiple choice technology programming languages
  1. True

  2. False

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

A TreeSet relies on natural ordering or a comparator to sort its elements. When adding elements, it compares them using compareTo(). Comparing a String to an Integer throws a ClassCastException at runtime because they are incompatible types.

Multiple choice technology programming languages
  1. abstract class Link { }

  2. native class Link { }

  3. final class Link { }

  4. abstract final class Link { }

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

In Java, the final modifier prevents a class from being subclassed (extended). The abstract modifier requires a class to be extended, making abstract final an illegal combination. native is not a valid modifier for classes.