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 web technology
  1. One

  2. Two

  3. None

  4. Mamy

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

A .NET DLL (assembly) can contain unlimited multiple classes - there's no technical restriction. The option D 'Mamy' appears to be a typo for 'Many', but it's clearly the intended correct answer. DLLs are designed to package multiple types together. Options A (One), B (Two), and C (None) are incorrect because DLLs routinely contain many classes in real-world applications.

Multiple choice technology web technology
  1. Server-side code

  2. Client-side code

  3. Both A) and B)

  4. None of the above

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

Code-behind classes in ASP.NET contain server-side code that executes on the web server. This code handles events, performs business logic, and interacts with databases before the page is rendered to HTML. Client-side code like JavaScript would be in script tags or .js files, not in code-behind classes.

Multiple choice technology web technology
  1. System.Diagnostics.Process

  2. System.Object class

  3. System.Drawing namespace

  4. None of the Above

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

In VB.NET, if Option Strict is turned off and a variable is declared without an explicit type (e.g., Dim x), the compiler defaults its type to System.Object, which is the root of the .NET type hierarchy.

Multiple choice technology web technology
  1. In VB.NET a child Class can Inherit from 2 Parent Classes

  2. Inheritance concept is not supported by .NET

  3. Both A) and B)

  4. None of the Above

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

VB.NET does not support multiple inheritance from classes (only single inheritance with multiple interface implementation). .NET fully supports inheritance as a core object-oriented concept. Both statements A and B are false.

Multiple choice technology web technology
  1. Single inheritance using classes

  2. Multiple inheritance using interfaces

  3. Both A) and B)

  4. None of the Above

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

VB.NET supports single inheritance for classes (a class can inherit from only one base class) and multiple inheritance for interfaces (a class or interface can implement/inherit multiple interfaces).

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.