Q.1 Which of the following is NOT a pillar of Object-Oriented Programming?
Encapsulation
Polymorphism
Abstraction
Iteration
Explanation - The four main pillars of OOP are Encapsulation, Polymorphism, Abstraction, and Inheritance. Iteration is a programming concept but not a pillar of OOP.
Correct answer is: Iteration
Q.2 In OOP, which feature allows using the same method name but with different arguments?
Inheritance
Method Overloading
Encapsulation
Abstraction
Explanation - Method Overloading allows multiple methods in the same class with the same name but different parameter lists.
Correct answer is: Method Overloading
Q.3 Which OOP concept ensures that internal object details are hidden from the outside world?
Polymorphism
Abstraction
Encapsulation
Inheritance
Explanation - Encapsulation hides the internal state of an object and only exposes necessary functionality through public methods.
Correct answer is: Encapsulation
Q.4 What is the process of creating a new class from an existing class called?
Encapsulation
Polymorphism
Inheritance
Abstraction
Explanation - Inheritance allows a new class (child) to acquire properties and behaviors of an existing class (parent).
Correct answer is: Inheritance
Q.5 In OOP, which keyword is commonly used in Java to inherit a class?
extends
implements
inherits
superclass
Explanation - In Java, the keyword 'extends' is used to indicate that a class is inheriting another class.
Correct answer is: extends
Q.6 Which OOP feature allows objects of different classes to be treated as objects of a common superclass?
Polymorphism
Inheritance
Abstraction
Encapsulation
Explanation - Polymorphism enables one interface to be used for different types of objects, typically through method overriding.
Correct answer is: Polymorphism
Q.7 Which of the following best describes an 'abstract class'?
A class with no methods
A class that cannot be instantiated
A class with only static methods
A class that hides all data
Explanation - Abstract classes serve as blueprints for other classes and cannot be instantiated directly.
Correct answer is: A class that cannot be instantiated
Q.8 Which access modifier makes class members accessible only within the same class?
public
protected
private
default
Explanation - The 'private' modifier restricts access to members within the class itself.
Correct answer is: private
Q.9 In OOP, constructors are mainly used for?
Destroying objects
Creating classes
Initializing objects
Hiding data
Explanation - Constructors are special methods used to initialize objects when they are created.
Correct answer is: Initializing objects
Q.10 Which OOP principle helps in code reuse?
Polymorphism
Abstraction
Inheritance
Encapsulation
Explanation - Inheritance allows one class to reuse fields and methods of another class, promoting code reuse.
Correct answer is: Inheritance
Q.11 Which method is called automatically when an object is destroyed?
Destructor
Constructor
Overloader
Initializer
Explanation - Destructors are invoked automatically to clean up resources when an object goes out of scope.
Correct answer is: Destructor
Q.12 In C++, which symbol is used for defining a class member as a pointer?
&
*
->
::
Explanation - The asterisk (*) is used to define a pointer type in C++.
Correct answer is: *
Q.13 Which keyword in Java is used to prevent a class from being inherited?
private
sealed
final
static
Explanation - In Java, the 'final' keyword prevents further inheritance of a class.
Correct answer is: final
Q.14 What is the relationship called when a class contains objects of another class?
Inheritance
Polymorphism
Composition
Abstraction
Explanation - Composition means building complex objects by combining simpler ones, often described as a 'has-a' relationship.
Correct answer is: Composition
Q.15 Which OOP concept binds data and methods together as a single unit?
Polymorphism
Inheritance
Encapsulation
Abstraction
Explanation - Encapsulation ensures that data and behavior are bundled together in one class.
Correct answer is: Encapsulation
Q.16 Which method in Java is called when printing an object?
print()
display()
toString()
output()
Explanation - The toString() method in Java returns a string representation of an object when printed.
Correct answer is: toString()
Q.17 In OOP, overriding happens when:
Two methods in the same class have the same name but different parameters
A subclass provides its own implementation of a method from the parent class
Two methods in the same class have different return types
Multiple classes have unrelated methods
Explanation - Overriding lets subclasses give specific implementations to methods defined in the parent class.
Correct answer is: A subclass provides its own implementation of a method from the parent class
Q.18 Which feature of OOP reduces code duplication by enabling a class to inherit from multiple classes (in some languages)?
Single Inheritance
Multiple Inheritance
Polymorphism
Encapsulation
Explanation - Multiple inheritance allows a class to inherit features from more than one parent class, supported in languages like C++.
Correct answer is: Multiple Inheritance
Q.19 Which keyword in C++ is used to declare a virtual function?
virtual
abstract
override
super
Explanation - The 'virtual' keyword in C++ allows functions to be overridden in derived classes, enabling polymorphism.
Correct answer is: virtual
Q.20 Which of these is a constructor in C++?
void constructor()
ClassName()
new ClassName()
create()
Explanation - In C++, a constructor has the same name as the class and no return type.
Correct answer is: ClassName()
Q.21 In OOP, which concept allows a class to define methods that must be implemented in derived classes?
Encapsulation
Abstract Class
Static Methods
Private Inheritance
Explanation - Abstract classes can declare abstract methods that derived classes must implement.
Correct answer is: Abstract Class
Q.22 Which of these is true about interfaces in Java?
They can have constructors
They cannot have any methods
They can have abstract methods
They can be instantiated
Explanation - Interfaces in Java define abstract methods that must be implemented by classes.
Correct answer is: They can have abstract methods
Q.23 In OOP, the 'this' keyword refers to:
The parent class
The current object
The superclass constructor
The main method
Explanation - The 'this' keyword refers to the current object instance of the class.
Correct answer is: The current object
Q.24 Which type of relationship is represented by 'is-a'?
Composition
Aggregation
Inheritance
Encapsulation
Explanation - 'is-a' represents Inheritance, where a subclass is a type of the superclass.
Correct answer is: Inheritance
Q.25 Which of the following is true for encapsulation?
Data and functions are separated
Only data is hidden
Data and functions are combined into a class
Encapsulation only applies to functions
Explanation - Encapsulation bundles data and methods together in a class.
Correct answer is: Data and functions are combined into a class
