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 architecture
  1. A pointcut

  2. a join Point

  3. an Aspect

  4. None

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

An Aspect is a Java class that encapsulates one or more advices (logic like logging, security, transactions) applied to multiple points in an application. A pointcut defines WHERE advice is applied, and a join point is a specific execution point where advice can be applied. The aspect class contains both pointcuts and advices.

Multiple choice technology programming languages
  1. Parent Class

  2. Class

  3. Child Class

  4. None Of Above

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

In Java, a superclass is the parent class that is being extended. When class B extends class A, class A is the superclass (parent) and class B is the subclass (child). Superclass provides attributes and methods that subclasses inherit.

Multiple choice technology programming languages
  1. Instance of Class

  2. Static Variable

  3. Keyword

  4. None Of above

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

An object is a concrete instance of a class. When you write 'MyClass obj = new MyClass()', obj is the object/instance and MyClass is the class template. Objects have state (fields) and behavior (methods).

Multiple choice technology architecture
  1. decouple an abstraction from its implementation so that the two can vary independently

  2. One class takes in another class, both of which extend the same abstract class, and adds functionality.

  3. Assembles group of objects with same signature

  4. One class controls the creation of and access to objects in another class.

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

The Decorator pattern attaches additional responsibilities to an object dynamically. It wraps an object (both implement the same interface) to add behavior without modifying the original class, providing a flexible alternative to subclassing for extending functionality.

Multiple choice technology architecture
  1. The reusable and variable parts of a class are broken into two classes to save resources

  2. One class controls the creation of and access to objects in another class.

  3. One class takes in another class, both of which extend the same abstract class, and adds functionality.

  4. One class has a method that performs a complex process calling several other classes.

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

The Facade pattern provides a simplified interface to a complex subsystem. One class exposes a high-level interface that coordinates multiple underlying classes, making the subsystem easier to use without exposing its complexity.

Multiple choice technology architecture
  1. Adapter, Bridge and Decorator.

  2. Singleton, Builder and Factory Method.

  3. Facade, Flyweight and Proxy.

  4. Iterator, Observer and Template.

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

Creational patterns deal with object creation mechanisms. Singleton ensures only one instance exists, Builder constructs complex objects step-by-step, and Factory Method defines an interface for creating objects but lets subclasses decide which class to instantiate. Options A and C are structural patterns, while D are behavioral patterns.

Multiple choice technology architecture
  1. Decorator Pattern.

  2. Façade Pattern.

  3. Proxy Pattern.

  4. Adapter Pattern.

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

The Proxy Pattern provides a surrogate or placeholder for another object to control access to it. A proxy typically has the same interface as the real object because it implements a common interface or extends an abstract class, enabling it to act as a direct stand-in.

Multiple choice technology architecture
  1. Strategy Pattern.

  2. Template Pattern.

  3. Observer Pattern.

  4. None of the above.

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

The Template Method pattern defines the skeleton of an algorithm in a method, deferring some steps to subclasses. It implements invariant parts of an algorithm once in the base class while allowing subclasses to override the variable parts. This promotes code reuse and enforces algorithm structure.

Multiple choice technology architecture
  1. Composite Pattern

  2. Strategy Pattern

  3. Observer Pattern

  4. Factory Pattern

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

The Composite pattern composes objects into tree structures to represent part-whole hierarchies. It allows clients to treat individual objects and compositions of objects uniformly through recursive composition, enabling complex objects to be built from simpler ones using the same interface.

Multiple choice technology architecture
  1. Façade Pattern.

  2. Adapter Pattern

  3. Strategy Pattern.

  4. Factory pattern.

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

The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. It allows different implementations of an algorithm to be selected dynamically at runtime without changing the client code that uses the strategy, promoting flexibility and separation of concerns.

Multiple choice technology architecture
  1. Singleton Pattern

  2. Façade Pattern.

  3. Factory Pattern.

  4. Adapter Pattern.

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

Factory Pattern is specifically designed to defer instantiation decisions to subclasses or factory methods, allowing the runtime selection of which compatible class to instantiate without the client knowing the concrete class. Singleton ensures only one instance exists. Facade provides a simplified interface to a complex subsystem. Adapter makes incompatible interfaces work together.

Multiple choice technology architecture
  1. Command

  2. Interpreter

  3. Mediator.

  4. Iterator.

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

Iterator Pattern provides a way to access elements of an aggregate object sequentially without exposing its underlying representation - exactly what the question describes. Command encapsulates requests. Interpreter evaluates language expressions. Mediator defines centralized communication between objects.