Computer Knowledge

Object-Oriented Programming

2,239 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. Class A 'is-a' Class B

  2. Class B 'is-a' Class A

  3. Class A 'has-a' Class B

  4. Class B 'has-a' Class A

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

Inheritance represents an 'is-a' relationship. When class B extends class A, B is a subclass of A, meaning 'Class B is-a Class A'. The reverse ('Class A is-a Class B') is incorrect because subclasses have more specific behavior. Composition represents 'has-a'.

Multiple choice technology web technology
  1. True

  2. False

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

Interfaces define abstract contracts with method signatures only, without implementation details like fields or method bodies. This is the fundamental purpose of interfaces - to specify what a type can do without defining how. Concrete types that implement interfaces provide the actual implementation. Therefore, the statement is false.

Multiple choice technology web technology
  1. multiple inheritance

  2. interface

  3. abstract

  4. None of the above

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

C# does not support multiple inheritance of classes to avoid the diamond problem and complexity. A class can only inherit from one base class. However, C# supports interfaces (option B) and abstract classes (option C), which are alternatives to achieve similar functionality. The correct answer is A - multiple inheritance (of classes) is not supported.

Multiple choice technology web technology
  1. Interface

  2. abstract class

  3. static class

  4. All the above

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

C# uses interfaces as the primary alternative to multiple inheritance. A class can implement multiple interfaces, gaining polymorphic behavior from each, while still inheriting implementation from only one base class. Abstract classes (option B) are single-inherited like regular classes. Static classes (option C) cannot be inherited at all. Therefore, interfaces are the correct alternative.

Multiple choice technology web technology
  1. Inheritance

  2. Composition

  3. Association

  4. Specialization

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

To solve this question, the user needs to have a basic understanding of object-oriented programming concepts.

The book and page relationship can be best characterized as a composition relationship. Composition is a "has-a" relationship between two or more classes, where one class is a part of another class. In this case, a book has one or more pages, and each page is a part of the book. Therefore, the best option is:

The Answer is: B (Composition)

Multiple choice technology web technology
  1. True

  2. False

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

Object diagrams show specific instances of classes with their actual attribute values at a given moment. While class diagrams define the structure and relationships, object diagrams require runtime state information and specific instance data that cannot be derived from class definitions alone. You need to know what objects actually exist and their current state to create an object diagram.

Multiple choice technology programming languages
  1. Interface

  2. Class

  3. Abstract Class

  4. Filter

  5. None

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

GenericServlet is an abstract class in the Java Servlet API, not an interface or concrete class. It implements the Servlet interface and provides basic implementations for most methods, except service() which remains abstract. Subclasses must implement service().

Multiple choice technology programming languages
  1. Interface

  2. Class

  3. Abstract Class

  4. All

  5. None

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

Abstract classes can have both abstract methods (without implementation) and concrete methods (with implementation). This allows partial implementation - some methods are implemented, others are left abstract for subclasses to implement. Interfaces require all methods to be implemented by the implementing class, and concrete classes must provide complete implementation.

Multiple choice technology programming languages
  1. Interface

  2. Class

  3. Abstract Class

  4. Filter

  5. None

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

GenericServlet is an abstract class in Java Servlet API that implements the Servlet interface. It provides basic implementation of most Servlet methods except service(), which must be implemented by subclasses. HttpServlet extends GenericServlet to provide HTTP-specific functionality. GenericServlet is not an interface, not a concrete class, and not a Filter.

Multiple choice technology programming languages
  1. Interface

  2. Class

  3. Abstract Class

  4. All

  5. None

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

Abstract classes are designed specifically to provide partial implementation - they can have both abstract methods (without implementation) and concrete methods (with implementation). Interfaces require all methods to be implemented (before Java 8) and regular classes must provide complete implementations. Only abstract classes allow the flexibility of implementing some methods while leaving others for subclasses to complete.

Multiple choice technology platforms and products
  1. Can create instances of concrete classes

  2. Must have patterns & direct inheritance

  3. Must have direct inheritance and need not have pattern inheritance.

  4. Need not have either pattern or direct inheritance

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

Concrete classes in Pega are classes from which instances can be created (option A is correct). They must have direct inheritance (a parent class) but are not required to have pattern inheritance (option C is correct). Pattern inheritance is optional for concrete classes, so they need not have it (making C correct, not B). Option D is incorrect because they must have at least direct inheritance.

Multiple choice technology programming languages
  1. List<string>

  2. IEnumerable<string>

  3. List<object>

  4. IEnumerable<object>

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

The Where() extension method on List returns IEnumerable, the deferred execution sequence interface. This is the standard LINQ return type for filtering operations. The actual runtime type is a nested iterator class, but the declared return type is IEnumerable. It is not List or the object variant.

Multiple choice technology programming languages
  1. True

  2. False

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

Static methods belong to the class itself, not to any specific instance. They can only access static variables (class variables) and cannot directly reference instance variables, which require an object instance to exist. This is a fundamental Java concept regarding method types and variable scope.

Multiple choice technology web technology
  1. Two methods defined in that interface

  2. Only certain methods in an interface

  3. Any methods in a class

  4. All methods defined in that interface

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

When a class implements an interface, it enters a contract to provide concrete implementations for ALL methods declared in that interface. This is a fundamental Java principle - interfaces define what a class MUST do, and the implementing class provides the specific behavior for every method.