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. Classes that are both in the same assembly and derived from the declaring class.

  2. Only methods that are in the same class as the method in question.

  3. Internal methods can be only be called using reflection.

  4. Classes within the same assembly, and classes derived from the declaring class.

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

The protected internal access modifier in C# represents a logical OR combination, allowing access from any code within the same assembly, or from derived classes in other assemblies. It does not require classes to be both in the same assembly and derived, making that distractor incorrect.

Multiple choice technology programming languages
  1. Encapsulating an object in a value type.

  2. Encapsulating a copy of an object in a value type.

  3. Encapsulating a value type in an object.

  4. Encapsulating a copy of a value type in an object.

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

Boxing in .NET is the process of converting a value type (such as int or struct) to a reference type (object). When you box a value, the CLR creates a new object on the heap and copies the value type's contents into it. This is different from simply encapsulating an object (which is already a reference type).

Multiple choice technology programming languages
  1. The conversion of one type of object to another.

  2. The runtime resolution of method calls.

  3. The exposition of data.

  4. The separation of interface and implementation.

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

Encapsulation in OOP is the practice of hiding internal implementation details while exposing only necessary functionality through a public interface. This bundling of data with methods that operate on that data, and controlling access through visibility modifiers (private, public, protected), enables information hiding and reduces system complexity. Options A and C describe type casting and exposure (the opposite of encapsulation), while B describes polymorphism.

Multiple choice technology architecture
  1. Chain of responsibility

  2. Adapter

  3. Decorator

  4. Composite

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

The Decorator design pattern attaches additional responsibilities to an object dynamically without affecting other objects of the same class. It provides a flexible alternative to subclassing for extending functionality by wrapping the original object and adding behavior at runtime. Chain of Responsibility handles request passing, Adapter converts interfaces, and Composite composes objects into tree structures.

Multiple choice technology architecture
  1. Abstract Factory

  2. Factory Method

  3. Builder

  4. Prototype

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

The Factory Method pattern defines an interface for creating an object but lets subclasses decide which class to instantiate. It defers instantiation to subclasses, allowing a class to delegate instantiation to child classes. Abstract Factory creates families of related objects, Builder constructs complex objects step-by-step, and Prototype clones existing objects.

Multiple choice technology architecture
  1. Chain of responsibility

  2. Template method

  3. Interpreter

  4. Mediator

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

The Template Method pattern defines the skeleton of an algorithm in a base class, allowing subclasses to override specific steps without changing the overall structure. This promotes code reuse and ensures the algorithm's invariant steps remain consistent while enabling customization of variable steps. Chain of Responsibility handles request passing through a chain, Interpreter interprets grammar, and Mediator centralizes communication between objects.

Multiple choice technology programming languages
  1. flouted

  2. routed

  3. scouted

  4. touted

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

Early literature on OOP often 'touted' (promoted or praised as a major advantage) that objects map naturally to real-world objects. 'Touted' means highlighted or recommended enthusiastically, which fits the context of promoting OOP benefits.

Multiple choice technology programming languages
  1. obtuse

  2. abstract

  3. abstruse

  4. oblique

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

The sentence states that object mapping encourages thinking in the problem domain rather than 'abstract' computer science terms. This means focusing on concrete, domain-specific concepts instead of theoretical computing abstractions.

Multiple choice technology programming languages
  1. class Application1

  2. public class Application1

  3. public static void Application1

  4. static Application1

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

For a standalone class that serves as the application entry point, it must be declared public. "public class Application1" is the proper declaration. Option A lacks the public modifier needed for a main class, while options C and D use incorrect syntax.

Multiple choice technology programming languages
  1. An instance of the Student class

  2. The course variable

  3. The gradeStudent method

  4. The ID variable

  5. The name variable

Reveal answer Fill a bubble to check yourself
B,C,D,E Correct answer
Explanation

In Java inheritance, a subclass inherits all accessible instance variables (name, ID, course) and methods (gradeStudent) from its superclass. It does not inherit an instance - that's not how inheritance works.

Multiple choice technology programming languages
  1. mMemberAttribute

  2. mmemberAttribute

  3. MemberAttribute

  4. member_attribute

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

mMemberAttribute follows the class attribute guideline - 'm' prefix indicates member variable, followed by camelCase. mmemberAttribute (double m), MemberAttribute (no prefix), and member_attribute (snake_case) all violate the naming convention.

Multiple choice technology architecture
  1. DataMemberAttribute, Public

  2. ServiceContractAttribute, Public

  3. DataMemberAttribute,Private

  4. DataContractAttribute,Public

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

DataContractSerializer serializes members marked with DataMemberAttribute regardless of access level (public or private). XmlSerializer only serializes public members by default. This is a key distinction - DataContract gives you more control over what gets serialized, while XmlSerializer follows traditional .NET serialization patterns.

Multiple choice technology web technology
  1. Inversion Injection

  2. Dependency Injection

  3. Setter Injection

  4. Pattern Injection

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

Inversion of Control (IoC) is a design principle where the flow of control is inverted compared to traditional programming. Dependency Injection is a common implementation pattern for achieving IoC - dependencies are provided to objects rather than objects creating them. Setter Injection and Constructor Injection are specific types of Dependency Injection.