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
  1. An object is the instantiation of a class.

  2. A class is the implementation of an object.

  3. An object is the implementation of a class.

  4. A class is the instantiation of an object.

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

 In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system.So option 1 is true..

Multiple choice
  1. Yes

  2. No

  3. Can't tell

  4. May be

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

Private members ARE inherited in the class structure but are NOT accessible in derived classes. Inheritance includes all members, but access modifiers control visibility. The 'Yes' answer refers to structural inheritance, not accessibility.

Multiple choice
  1. Declare the class as final.

  2. Declare the class as shadows.

  3. Declare the class as sealed.

  4. Declare the class as overrides.

  5. Declare the class as abstract.

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

Classes declared with sealed keyword cannot be used as base class for other classes. They must be instantiated to be used.

Multiple choice
  1. A class can inherit a base class and can also implement one or more interfaces.

  2. An interface cannot contain the definition of a method.

  3. An interface can inherit from one or more base interfaces.

  4. An interface cannot contain an event.

  5. Interface members are by default public.

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

Interfaces can contain methods, properties, events, indexers or any combination of those four member types.

Multiple choice
  1. Delegates are type-safe.

  2. Delegates are reference types.

  3. Delegates serve the same purpose as function pointers in C and pointers to member function operators in C++.

  4. Only one method can be called using a delegate.

  5. A delegate does not know about the class of the object that it references.

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

A delegate can call more than one methods. A delegate that can have more than one element in its invocation list is known as MultiCast Delegate.

Multiple choice
  1. There can be only one static constructor in the class.

  2. The static constructor can be parameterised.

  3. It can only access the static members of the class.

  4. There should be no access modifier in static constructor definition.

  5. The static keyword is used to declare a static constructor.

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

The static constructor should be without parameters. If a static constructor is declared parameterised, the compiler will display an error.

Multiple choice
  1. Common Type System

  2. Common Language Runtime

  3. .NET Framework Class Library

  4. None of these

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

Common Type System is a component of CLR that ensures that all .NET applications use the same data types regardless of what programming languages were used to develop the application.

 

Multiple choice
  1. System

  2. Console

  3. WriteLine

  4. None of the above

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

The above written line contains the namespace System. Console, which is the class used to write on to the console and the WriteLine is the method to write the line on the screen.