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

  2. False

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

To solve this question, the user needs to have knowledge of Java programming language.

The statement is True.

In Java, a source file is officially called a "compilation unit". It contains the source code for a single Java class or interface. When the Java compiler compiles the source code, it generates a bytecode file for each compilation unit, which can then be executed on any platform that has a Java Virtual Machine (JVM). Therefore, option A is correct.

The Answer is: A. True

Multiple choice technology programming languages
  1. True

  2. False

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

In object-oriented programming, a class can implement multiple interfaces. Interfaces define contracts without implementation, and a class can conform to multiple contracts simultaneously. This is a fundamental OOP principle that enables flexible design and multiple inheritance of type specifications without the complexities of multiple inheritance of implementation.

Multiple choice technology programming languages
  1. Parameter

  2. Value

  3. Index

  4. Object

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

In many programming languages, the implicit parameter name for a property setter is 'value'. This is a convention where the setter receives the new value to be assigned to the property. For example, in C# and VB.NET, 'value' is the implicit keyword that represents the parameter being assigned to the property.

Multiple choice technology programming languages
  1. One

  2. Two

  3. Nill

  4. None

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

Once you define any constructor in C#, the compiler no longer provides the default parameterless constructor. To keep a parameterless constructor along with your parameterized one, you must explicitly write both constructors.

Multiple choice technology programming languages
  1. True

  2. False

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

Private methods cannot be overridden because they are not accessible outside the class in which they are defined. Overriding requires the method to be visible to derived classes, and private methods are explicitly restricted to the defining class only. Even if a private method is marked virtual, the private access modifier takes precedence for accessibility.

Multiple choice technology architecture
  1. Defines multiple access points for a singleton

  2. supports multiple visibility forms for a singleton

  3. allows the creation of multiple class instances in the future without affecting the clients of the singleton class

  4. All of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Multiple choice technology architecture
  1. Allows you to represent composite objects in the form of a hierarchy

  2. It uses independent interfaces for representing individual and composite objects

  3. It uses an individual object that is composed of two or more composite objects

  4. It represents just a collection of different objects

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

The Composite pattern's key concept is representing part-whole hierarchies of objects, allowing clients to treat individual objects and compositions uniformly. This enables tree structures of objects where a parent node can have multiple children. Option A correctly captures this hierarchical representation concept.

Multiple choice technology architecture
  1. Adapter pattern is used to access facades

  2. The Adapter pattern adds an indirection object for low coupling

  3. The Façade pattern hides the complexity of a subsystem from a client

  4. None of the above

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

The Facade pattern provides a simplified interface to a complex subsystem, hiding its complexity from clients. This reduces coupling and makes the subsystem easier to use. Option C correctly states this purpose. Options A and B incorrectly reference the Adapter pattern.

Multiple choice technology architecture
  1. Assigns responsibility to an intermediate object

  2. Creates a convenient class that supports high cohesion and low coupling

  3. Creates a convenient class that supports low cohesion and high coupling

  4. Protects the system from unexpected variations

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

The Pure Fabrication pattern is a GRASP pattern that creates an artificial class to support high cohesion and low coupling when no existing domain class is appropriate. It helps assign responsibilities that don't naturally fit into domain objects. Option B correctly captures this concept.

Multiple choice technology architecture
  1. Handles the message generated when a system event or operation takes place

  2. assigns the responsibility for creating new class instance or object

  3. Determine how a system handles conditional variations

  4. Creates a convenient class

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

The Polymorphism pattern in GRASP deals with handling variation and alternatives by assigning responsibility to varying behaviors to the types that need them. It determines how a system should handle conditional variations using polymorphic operations rather than explicit conditional logic. Option C correctly identifies this.

Multiple choice technology architecture
  1. Is a behavioral pattern that defines how a single class can be notified of a change

  2. Consider the objects displaying the data and the objects containing the data as a single entity.

  3. Is also known as the publish-subscribe model where an object can publish an event that has no subscribers

  4. None of the above

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

The Observer pattern (also called Publish-Subscribe) defines a one-to-many dependency between objects, so that when one object changes state, all its dependents are notified and updated automatically. Publishers (subjects) maintain a list of subscribers (observers) and notify them of state changes. Option C correctly identifies this as the publish-subscribe model and notes that events can have zero subscribers (publishing is independent of subscription). Option A incorrectly limits notification to a single class. Option B incorrectly suggests Observer merges data and display into one entity, when it actually separates them. Option D is incorrect since option C is valid.

Multiple choice technology programming languages
  1. Yes

  2. No

  3. Can't Say

  4. I don't know

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

C# absolutely supports private constructors. They're commonly used in design patterns like Singleton to prevent direct instantiation from outside the class, or for static utility classes that should never be instantiated. The private constructor can only be called from within the class itself, typically through a static method or property that controls instance creation.