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
-
An object is the instantiation of a class.
-
A class is the implementation of an object.
-
An object is the implementation of a class.
-
A class is the instantiation of an object.
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..
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.
-
Reference Parameters
-
Output Parameters
-
Aliases
-
Both (1) and (2)
A
Correct answer
Explanation
Reference parameters (ref) MUST be initialized before being passed to a method. Output parameters (out) do not require initialization. Aliases refers to ref parameters. The answer A (Reference Parameters) is correct.
-
Declare the class as final.
-
Declare the class as shadows.
-
Declare the class as sealed.
-
Declare the class as overrides.
-
Declare the class as abstract.
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.
-
Private and Public
-
Protected and Public
-
Private and Protected
-
Static and Public
-
Static and Protected
B
Correct answer
Explanation
The protected and public members of a base class can be accessed from the derived class.
-
A class can inherit a base class and can also implement one or more interfaces.
-
An interface cannot contain the definition of a method.
-
An interface can inherit from one or more base interfaces.
-
An interface cannot contain an event.
-
Interface members are by default public.
D
Correct answer
Explanation
Interfaces can contain methods, properties, events, indexers or any combination of those four member types.
-
Delegates are type-safe.
-
Delegates are reference types.
-
Delegates serve the same purpose as function pointers in C and pointers to member function operators in C++.
-
Only one method can be called using a delegate.
-
A delegate does not know about the class of the object that it references.
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.
-
There can be only one static constructor in the class.
-
The static constructor can be parameterised.
-
It can only access the static members of the class.
-
There should be no access modifier in static constructor definition.
-
The static keyword is used to declare a static constructor.
B
Correct answer
Explanation
The static constructor should be without parameters. If a static constructor is declared parameterised, the compiler will display an error.
-
Polymorphism
-
Templates
-
Inheritance
-
Containership
-
Encapsulation
C
Correct answer
Explanation
When a class derives it functionality (methods and properties) from another class, it is known as inheritance. The derived class can access all the non-private data and behaviour of the base class.
-
Value type
-
Reference type
-
Implicit data type
-
Explicit data type
A
Correct answer
Explanation
Value types are passed to methods by passing an exact copy.
-
Class
-
Instantiation
-
Object
-
None of these
C
Correct answer
Explanation
An object is a self-contained unit that combines code and data.
-
Common Type System
-
Common Language Runtime
-
.NET Framework Class Library
-
None of these
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.
-
Events
-
Class
-
Methods
-
None of these
A
Correct answer
Explanation
Events are signals by which an object can notify other objects that something noteworthy has occurred.
-
System
-
Console
-
WriteLine
-
None of the above
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.
-
System
-
Object
-
Class
-
System.Object
D
Correct answer
Explanation
System.Object is the predefined or default type to which all the variables or any other component of .NET based program adhere to.