By: Prof. Dr. Fazal Rehman | Last updated: February 20, 2024
What is the primary goal of object-oriented programming? a. Code efficiency
b. Code modularity
c. Code reusability
d. Code optimization
Answer: c. Code reusability
Which of the following is not a fundamental concept of object-oriented programming? a. Inheritance
b. Encapsulation
c. Polymorphism
d. Iteration
Answer: d. Iteration
What is the process of combining data and code into a single unit known as? a. Encapsulation
b. Inheritance
c. Polymorphism
d. Abstraction
Answer: a. Encapsulation
In object-oriented programming, what is a class? a. An instance of an object
b. A blueprint for creating objects
c. A variable within an object
d. A method for accessing class members
Answer: b. A blueprint for creating objects
What is the term for creating a new object based on an existing object? a. Inheritance
b. Composition
c. Encapsulation
d. Instantiation
Answer: d. Instantiation
What is polymorphism in object-oriented programming? a. The ability of a class to inherit from multiple classes
b. The ability of a class to have multiple methods with the same name
c. The ability of a class to hide its internal implementation
d. The ability of a class to encapsulate its data
Answer: b. The ability of a class to have multiple methods with the same name
Which principle of OOP states that a subclass should be able to replace its parent class without affecting the program’s correctness? a. Encapsulation
b. Polymorphism
c. Inheritance
d. Abstraction
Answer: c. Inheritance
What is the concept of hiding the internal details of an object and only exposing the necessary functionality? a. Inheritance
b. Encapsulation
c. Polymorphism
d. Abstraction
Answer: d. Abstraction
What is the purpose of the “super” keyword in Java and similar languages? a. Refers to the superclass
b. Refers to the subclass
c. Refers to the current instance of the class
d. Refers to the static members of the class
Answer: a. Refers to the superclass
Which keyword is used to implement method overriding in Java? a. virtual
b. override
c. final
d. extends
Answer: b. override
What is the term for a blueprint of an object that defines its properties and behaviors? a. Object
b. Class
c. Method
d. Instance
Answer: b. Class
Which OOP concept allows a class to have multiple methods with the same name but different parameters? a. Inheritance
b. Encapsulation
c. Overloading
d. Polymorphism
Answer: c. Overloading
What is the term for the ability of an object to take on multiple forms based on its context? a. Inheritance
b. Polymorphism
c. Abstraction
d. Encapsulation
Answer: b. Polymorphism
In OOP, what is a constructor? a. A method that initializes an object’s state
b. A variable that holds the object’s data
c. A class that extends another class
d. An interface for defining methods
Answer: a. A method that initializes an object’s state
What is the term for the ability of a class to inherit from more than one class? a. Multiple inheritance
b. Multilevel inheritance
c. Hierarchical inheritance
d. Single inheritance
Answer: a. Multiple inheritance
What does the term “this” refer to in object-oriented programming? a. Refers to the superclass
b. Refers to the current instance of the class
c. Refers to the subclass
d. Refers to the static members of the class
Answer: b. Refers to the current instance of the class
Which OOP concept allows a class to inherit properties and behaviors from more than one class? a. Inheritance
b. Encapsulation
c. Polymorphism
d. Multiple inheritance
Answer: d. Multiple inheritance
In OOP, what is the term for creating a new class based on an existing class? a. Aggregation
b. Composition
c. Instantiation
d. Inheritance
Answer: d. Inheritance
What is the term for the process of combining multiple objects to create a new object? a. Aggregation
b. Composition
c. Encapsulation
d. Instantiation
Answer: b. Composition
Which keyword is used for preventing further modification of a class or method in Java? a. override
b. final
c. abstract
d. static
Answer: b. final
What is the term for a method that has the same name as a method in the superclass and provides a specialized implementation? a. Overloading
b. Overriding
c. Encapsulation
d. Abstract method
Answer: b. Overriding
Which OOP concept allows a class to implement multiple interfaces? a. Inheritance
b. Encapsulation
c. Polymorphism
d. Interface implementation
Answer: a. Inheritance
What is the purpose of the “interface” keyword in Java and similar languages? a. Defines a concrete class
b. Declares a new data type
c. Implements multiple inheritance
d. Indicates a static method
Answer: b. Declares a new data type
Which OOP concept allows a class to have more than one method with the same name but different implementations? a. Inheritance
b. Polymorphism
c. Encapsulation
d. Abstraction
Answer: b. Polymorphism
What is the term for a method that has no implementation in the superclass and must be implemented by the subclass? a. Abstract method
b. Concrete method
c. Final method
d. Static method
Answer: a. Abstract method
What is the significance of the “protected” access modifier in OOP? a. Allows access only within the same class
b. Allows access within the same package and subclasses
c. Allows access from any class in the program
d. Prevents access from any class
Answer: b. Allows access within the same package and subclasses
Which of the following is not a principle of SOLID design in OOP? a. Single Responsibility Principle (SRP)
b. Open/Closed Principle (OCP)
c. Liskov Substitution Principle (LSP)
d. Nested Class Principle (NCP)
Answer: d. Nested Class Principle (NCP)
What is the term for the ability of a class to provide a generic interface to a group of related classes? a. Polymorphism
b. Abstraction
c. Inheritance
d. Encapsulation
Answer: b. Abstraction
Which keyword is used for method overloading in Java? a. over
b. load
c. method
d. overload
Answer: d. overload
In OOP, what is the term for creating a new class by combining multiple classes? a. Composition
b. Aggregation
c. Instantiation
d. Hybridization
Answer: a. Composition
What is the purpose of the “abstract” keyword in OOP? a. Specifies that a class cannot be instantiated
b. Specifies that a method must be implemented by the subclass
c. Specifies that a class cannot be inherited
d. Specifies that a method is static
Answer: a. Specifies that a class cannot be instantiated
What is the term for a class that cannot be instantiated and is typically used as a base class? a. Abstract class
b. Final class
c. Concrete class
d. Static class
Answer: a. Abstract class
In OOP, what is the term for a mechanism that allows a method to behave differently based on the object it is acting upon? a. Inheritance
b. Polymorphism
c. Abstraction
d. Encapsulation
Answer: b. Polymorphism
Which OOP principle suggests that a class should have only one reason to change? a. Single Responsibility Principle (SRP)
b. Open/Closed Principle (OCP)
c. Liskov Substitution Principle (LSP)
d. Interface Segregation Principle (ISP)
Answer: a. Single Responsibility Principle (SRP)
What is the term for a relationship between two classes where one class includes the other? a. Composition
b. Aggregation
c. Inheritance
d. Dependency
Answer: a. Composition
Which OOP principle states that a class should be open for extension but closed for modification? a. Single Responsibility Principle (SRP)
b. Open/Closed Principle (OCP)
c. Liskov Substitution Principle (LSP)
d. Interface Segregation Principle (ISP)
Answer: b. Open/Closed Principle (OCP)
What is the purpose of the “superclass” in OOP? a. Provides a generic interface to a group of related classes
b. Represents the parent class in inheritance
c. Hides the internal details of an object
d. Prevents further modification of a class
Answer: b. Represents the parent class in inheritance
Which OOP principle suggests that objects of a superclass should be able to replace objects of a subclass without affecting program behavior? a. Single Responsibility Principle (SRP)
b. Open/Closed Principle (OCP)
c. Liskov Substitution Principle (LSP)
d. Interface Segregation Principle (ISP)
Answer: c. Liskov Substitution Principle (LSP)
What is the term for a relationship between two classes where one class is a part of the other and can exist independently? a. Composition
b. Aggregation
c. Inheritance
d. Dependency
Answer: b. Aggregation
Which keyword is used to declare a variable that can reference objects of multiple classes in Java? a. var
b. any
c. polymorphic
d. Object
Answer: d. Object
What is the purpose of the “interface” in OOP? a. Represents a specific type of object
b. Declares a set of methods without implementation
c. Implements a set of methods with default behavior
d. Specifies the visibility of class members
Answer: b. Declares a set of methods without implementation
Which OOP principle suggests that a class should not be forced to implement interfaces it does not use? a. Single Responsibility Principle (SRP)
b. Open/Closed Principle (OCP)
c. Liskov Substitution Principle (LSP)
d. Interface Segregation Principle (ISP)
Answer: d. Interface Segregation Principle (ISP)
In OOP, what is the term for a class that inherits from multiple classes? a. Derived class
b. Base class
c. Subclass
d. Hybrid class
Answer: a. Derived class
What is the term for a relationship between two classes where one class is dependent on the other? a. Composition
b. Aggregation
c. Inheritance
d. Dependency
Answer: d. Dependency
Which OOP principle suggests that a class should have a minimal number of methods and attributes? a. Single Responsibility Principle (SRP)
b. Open/Closed Principle (OCP)
c. Liskov Substitution Principle (LSP)
d. Law of Demeter (LoD)
Answer: a. Single Responsibility Principle (SRP)
What is the term for a method that has a common implementation in the superclass and can be overridden by the subclass? a. Abstract method
b. Concrete method
c. Final method
d. Static method
Answer: b. Concrete method
Which OOP concept allows a class to have more than one method with the same name and same parameters but different return types? a. Inheritance
b. Polymorphism
c. Encapsulation
d. Overloading
Answer: b. Polymorphism
In OOP, what is the term for creating a new class by combining properties and behaviors of multiple classes? a. Composition
b. Aggregation
c. Instantiation
d. Hybridization
Answer: d. Hybridization
What is the purpose of the “protected” keyword in OOP? a. Specifies that a class cannot be instantiated
b. Specifies that a method must be implemented by the subclass
c. Specifies that a class member can be accessed within the same package and subclasses
d. Specifies that a class member is static
Answer: c. Specifies that a class member can be accessed within the same package and subclasses
Which OOP principle suggests that a class should be easily extendable without modifying its existing code? a. Single Responsibility Principle (SRP)
b. Open/Closed Principle (OCP)
c. Liskov Substitution Principle (LSP)
d. Law of Demeter (LoD)