Object Oriented Programming - class, object, encapsulation, inheritance, polymorphism, abstract classes - Question Bank

1. The concept of 'object-oriented programming' was first popularized by which company?
A) Microsoft
B) IBM
C) Xerox
D) Apple
2. What is the fundamental difference between an abstract class and an interface in many OOP languages?
A) An interface can have concrete methods, while an abstract class cannot.
B) An abstract class can have instance variables, while an interface cannot.
C) An abstract class can implement multiple interfaces, but an interface cannot extend abstract classes.
D) An interface must be implemented, while an abstract class must be subclassed.
3. In OOP, inheritance allows a class to reuse code from another class. This promotes:
A) Duplication
B) Modularity
C) Reusability
D) Abstraction
4. What is the primary goal of abstraction in software design?
A) To make code as complex as possible.
B) To provide a high-level view while hiding implementation details.
C) To ensure all data is directly accessible.
D) To force code reuse through inheritance only.
5. Which OOP principle allows a single interface to represent multiple underlying forms?
A) Inheritance
B) Encapsulation
C) Polymorphism
D) Abstraction
6. What does the term 'object state' refer to in OOP?
A) The set of methods an object can perform.
B) The values of the object's attributes at a particular point in time.
C) The memory address of the object.
D) The class from which the object was created.
7. An abstract class can contain:
A) Only abstract methods.
B) Only concrete methods.
C) Both abstract and concrete methods.
D) No methods at all.
8. What is a key advantage of polymorphism?
A) It simplifies the process of writing code for diverse object types.
B) It eliminates the need for inheritance.
C) It forces all objects to have the same behavior.
D) It increases the complexity of method calls.
9. Which of the following best describes the concept of a 'class'?
A) A specific instance of data.
B) A collection of unrelated functions.
C) A user-defined data type that defines properties and behaviors.
D) A keyword used to define variables.
10. If a class `Shape` has a method `draw()`, and `Circle`, `Square`, `Triangle` classes inherit from `Shape` and override `draw()`, calling `draw()` on a `Shape` reference pointing to a `Circle` object will execute:
A) The `draw()` method in the `Shape` class.
B) The `draw()` method in the `Circle` class.
C) An error will occur.
D) The `draw()` method from the last derived class.
11. What is the primary purpose of data hiding in encapsulation?
A) To make data accessible to all other classes.
B) To protect the internal state of an object from unintended external modifications.
C) To reduce the amount of memory used by an object.
D) To allow direct access to private members.
12. A class that contains only abstract methods and no concrete methods or instance variables is often called an:
A) Abstract class
B) Concrete class
C) Interface
D) Utility class
13. What is a common way to achieve abstraction in OOP?
A) Using private variables extensively.
B) Creating objects directly from classes.
C) Using abstract classes and interfaces.
D) Implementing all methods within the base class.
14. Which OOP concept is most related to the idea of 'is-a' relationship?
A) Encapsulation
B) Inheritance
C) Polymorphism
D) Abstraction
15. What is a constructor in the context of a class?
A) A method used to destroy an object.
B) A special method called automatically when an object is created.
C) A method that returns the class name.
D) A method used for inheritance.
16. Polymorphism allows you to treat objects of different classes in a uniform way if they share a common:
A) Implementation
B) Constructor
C) Base class or interface
D) Private members
17. A method signature includes the method name and its:
A) Return type only
B) Access modifier only
C) Parameters
D) Body implementation
18. Encapsulation helps in making code more:
A) Open to modification
B) Dependent on external variables
C) Maintainable and secure
D) Less reusable
19. What is the main purpose of using abstract classes?
A) To enforce a common interface and structure for derived classes.
B) To prevent any further inheritance.
C) To provide a complete implementation for all derived classes.
D) To increase the runtime performance significantly.
20. Consider a `Dog` class and a `Cat` class, both inheriting from an `Animal` class. This is an example of:
A) Multilevel Inheritance
B) Hierarchical Inheritance
C) Multiple Inheritance
D) Hybrid Inheritance
21. What happens when you create an object from a class?
A) A new class is defined.
B) Memory is allocated for the object's data.
C) The class definition is destroyed.
D) All methods become abstract.
22. Which of the following is NOT a core principle of OOP?
A) Encapsulation
B) Inheritance
C) Proceduralism
D) Polymorphism
23. What is the term for a method defined in an abstract class that has no implementation?
A) Concrete method
B) Virtual method
C) Abstract method
D) Overridden method
24. A class that cannot be instantiated and is designed to be inherited from is typically:
A) A concrete class
B) An abstract class
C) A final class
D) An interface
25. Which OOP concept promotes code reuse by allowing classes to share common functionality?
A) Abstraction
B) Encapsulation
C) Polymorphism
D) Inheritance
26. What are the actions or functions that an object can perform called?
A) Attributes
B) Properties
C) Methods
D) Constructors
27. In OOP, what are the characteristics or properties of an object called?
A) Methods
B) Behaviors
C) Attributes
D) Classes
28. If a class `A` inherits from class `B`, and class `B` inherits from class `C`, this is an example of:
A) Multiple Inheritance
B) Multilevel Inheritance
C) Hierarchical Inheritance
D) Hybrid Inheritance
29. What does it mean for a class to be 'instantiable'?
A) It can be inherited by other classes.
B) It can have abstract methods.
C) Objects can be created from it.
D) It cannot be modified.
30. Which OOP principle helps in reducing complexity by modeling real-world entities?
A) Inheritance
B) Polymorphism
C) Abstraction
D) Encapsulation
31. What is the relationship between a class and an object?
A) An object is a blueprint for a class.
B) A class is an instance of an object.
C) A class is a blueprint, and an object is an instance of that blueprint.
D) They are interchangeable terms.
32. If a class has multiple methods with the same name but different parameter lists, this is an example of:
A) Runtime Polymorphism
B) Inheritance
C) Compile-time Polymorphism
D) Abstract Class
33. Consider a `Car` class inheriting from a `Vehicle` class. The `startEngine()` method is defined in `Vehicle` and overridden in `Car`. This is an example of:
A) Encapsulation
B) Abstraction
C) Compile-time Polymorphism
D) Runtime Polymorphism
34. What keyword is typically used to define an abstract class in many OOP languages?
A) static
B) final
C) abstract
D) virtual
35. An abstract method is a method that:
A) Has a complete implementation in the abstract class.
B) Is declared but not implemented in the abstract class.
C) Can only be called from within the abstract class.
D) Is automatically implemented by the compiler.
36. Which type of polymorphism allows a derived class to provide a specific implementation of a method that is already defined in its base class?
A) Compile-time Polymorphism (Overloading)
B) Runtime Polymorphism (Overriding)
C) Abstraction
D) Encapsulation
37. Which type of polymorphism allows a method to have the same name but different parameters in the same class?
A) Runtime Polymorphism (Overriding)
B) Compile-time Polymorphism (Overloading)
C) Inheritance
D) Encapsulation
38. What is the primary benefit of encapsulation?
A) Code reusability
B) Code flexibility
C) Data hiding and modularity
D) Runtime efficiency
39. A class that inherits from another class is called a:
A) Base class
B) Parent class
C) Superclass
D) Derived class
40. A class from which other classes inherit is called a:
A) Derived class
B) Child class
C) Base class
D) Subclass
41. Which OOP concept focuses on showing only essential features and hiding unnecessary details?
A) Encapsulation
B) Inheritance
C) Polymorphism
D) Abstraction
42. What is an abstract class in OOP?
A) A class that cannot be instantiated and may contain abstract methods.
B) A class that can only be instantiated once.
C) A class that is fully implemented and cannot be extended.
D) A class that automatically inherits from all other classes.
43. The ability of a function or method to perform different actions based on the object it is acting upon is called:
A) Inheritance
B) Encapsulation
C) Abstraction
D) Polymorphism
44. What OOP principle allows objects of different classes to respond to the same method call in their own specific ways?
A) Inheritance
B) Encapsulation
C) Polymorphism
D) Abstraction
45. The process of an object taking on the properties of another object is known as:
A) Composition
B) Aggregation
C) Inheritance
D) Association
46. In OOP, what concept allows a new class to derive properties and behaviors from an existing class?
A) Encapsulation
B) Inheritance
C) Polymorphism
D) Abstraction
47. What is the term for the mechanism that restricts direct access to some of an object's components, often referred to as 'data hiding'?
A) Inheritance
B) Polymorphism
C) Encapsulation
D) Abstraction
48. Which OOP principle involves bundling data (attributes) and methods (functions) that operate on the data within a single unit?
A) Inheritance
B) Polymorphism
C) Abstraction
D) Encapsulation
49. What is an instance of a class called in OOP?
A) Class
B) Method
C) Object
D) Attribute
50. In Object-Oriented Programming (OOP), what is a blueprint or a template for creating objects called?
A) Object
B) Class
C) Method
D) Variable