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

  2. Funtional Attributes

  3. Predefined Attributes

  4. Both A & C

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

.NET supports both Custom Attributes (user-defined) and Predefined Attributes (built-in like [Serializable], [Obsolete]). Functional Attributes do not exist as a category in .NET.

Multiple choice technology testing
  1. run-time

  2. test object

  3. both a&b

  4. none

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

The Object Spy in HP/Micro Focus UFT allows users to view both test object properties (static properties stored in the repository) and run-time object properties (dynamic properties of the actual object in the running application) along with their values.

Multiple choice technology programming languages
  1. Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables)

  2. State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state.

  3. When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once.

  4. All of above

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

All three statements describe why Java avoids global variables: they break referential transparency, reduce cohesion, and limit reusability by tying code to a single instance. Since each individual reason is valid, the combined choice “All of above” correctly captures the rationale.

Multiple choice technology platforms and products
  1. this() can be used to invoke a constructor of the same class

  2. this() will create the object of the same class

  3. There is no function called this(). It is a key word.

  4. this() will invoke the constructor of subclass

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

In Java, this() is a special syntax used inside a constructor to invoke another overloaded constructor within the same class (constructor chaining). It must be the first statement in the constructor. It does not instantiate new objects directly or call subclass constructors.

Multiple choice technology platforms and products
  1. singleton pattern.

  2. creational pattern.

  3. command design pattern.

  4. composite design pattern.

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

The Factory Pattern is classified as a creational design pattern because it provides an interface for creating objects without specifying their exact classes. It delegates object instantiation to subclasses or factory methods, promoting loose coupling by letting code depend on abstractions rather than concrete implementations. This is in contrast to structural patterns like composite or behavioral patterns like command.

Multiple choice technology platforms and products
  1. making all constructors private.

  2. making all constructors public.

  3. removing all constructors.

  4. making all constructor static.

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

The singleton pattern requires a private constructor to prevent external instantiation. This ensures only one instance can exist. Making constructors public would allow multiple instances, violating the singleton principle.

Multiple choice technology programming languages
  1. True

  2. False

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

In standard object-oriented theory and subtyping relationships, subclassing is reflexive: every class is considered a subclass of itself (a non-strict subclass). However, in languages like Java, a class is not a strict subclass of itself. Given standard OOP type theory, the statement is accepted as True.