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
-
data binding
-
polymorphism
-
encapsulation
-
inheritance
C
Correct answer
Explanation
Encapsulation is the OOP principle of hiding implementation details (data and method internals) from users of the class. This allows the class designer to modify internal implementation without affecting code that uses the class, as long as the public interface remains stable. Data binding, polymorphism, and inheritance are related but distinct concepts.
-
Static
-
Private
-
Public
-
Array
-
Assembly name
A
Correct answer
Explanation
This access modifier is used so that the method it is assigned to become a method of the class rather than an instance of the class.
-
Protected
-
Public
-
Private
-
Static modifier
-
Web service
A
Correct answer
Explanation
In this access modifier, access is limited to the containing class or types derived from the containing class.
-
public
-
private
-
protected
-
none of these
C
Correct answer
Explanation
In C++ inheritance, a protected member of the base class remains protected in the derived class when inherited in public mode. Public inheritance preserves the access level of protected members - they stay protected, not public. Private inheritance would make them private, and protected inheritance would keep them protected.
-
A static function can have access to only other static members declared in the same class.
-
A static function can be called using the class name instead of its objects.
-
The keyword static is used before the function name.
-
None of the above.
D
Correct answer
Explanation
All statements A, B, and C are correct about static member functions: they can only access other static members, can be called using class name, and the static keyword appears before the return type in declaration (not before the function name). Since all individual statements are true, 'None of the above' is technically incorrect, making D the answer choice.
A
Correct answer
Explanation
Polymorphism in OOP allows objects of different classes to be treated as objects of a common superclass. The core concept is one interface (function/operator name) with multiple implementations (forms). This includes function overloading, operator overloading, and virtual functions.
A
Correct answer
Explanation
In C++, destructors are special member functions that have the same name as the class but preceded by a tilde (~). They are automatically called when an object is destroyed to clean up resources like memory or file handles.
-
Base class-B
Derived class-C
-
Base class-A & B
Derived class-C
-
Base class-A
Derived class-B & C
-
Base class-A
Derived class-C
B
Correct answer
Explanation
Class C uses multiple inheritance, inheriting from both class A and class B (syntax: class C: public A,B). This makes A and B the base classes and C the derived class. Multiple inheritance allows a class to inherit from multiple base classes simultaneously.
-
the same as an abstract class
-
a data type that cannot be instantiated
-
a data type which can be used only by the defined operation
-
a data type on which operation defined can not use it
-
All of the above
C
Correct answer
Explanation
Correct answer; only the operation defined can use it.
-
a member of class
-
type of class
-
instance of class
-
independent like the class
-
part of the class
C
Correct answer
Explanation
Yes, in an object oriented programming language, an object is instance/variable of class. So, this option is correct.
-
Accessor function
-
Mutator function
-
Constructor function
-
Inline function
-
Destructor function
B
Correct answer
Explanation
This member function of a class modifies the values of the member variables.
-
Static binding
-
Late binding
-
Virtual function
-
Abstract class
-
Derived class
B
Correct answer
Explanation
This is the process of deciding which class function is to be called at runtime.
-
generated class
-
generated function
-
static member function
-
inline function
-
constructor function
B
Correct answer
Explanation
A function generated from a function template is called generated function.
-
Virtual function
-
Function overloading
-
Operator overloading
-
Inheritance
-
Encapsulation
A
Correct answer
Explanation
This function is used to make use of a function which is used in two derived classes and also in the base class without having any complexity in the program.
-
Public
-
Private
-
Protected
-
Not inherited
-
Public-Private
C
Correct answer
Explanation
This visibility mode is used when public and protected members of base class become protected members of derived class.