Object-oriented programming - Test
  • 1. Object-oriented programming (OOP) is a programming paradigm based on the concept of 'objects', which can contain data in the form of fields, and code in the form of procedures. Objects are instances of classes, which define the structure and behavior of the objects. OOP focuses on organizing code into reusable and modular components, allowing for better code organization and maintenance. Encapsulation, inheritance, and polymorphism are key concepts in OOP, providing mechanisms for data hiding, code reuse, and flexibility in implementation. By modeling real-world entities as objects, OOP promotes a clearer and more intuitive design approach to software development.

    What is the main concept behind object-oriented programming?
A) Polymorphism
B) Encapsulation
C) Abstraction
D) Inheritance
  • 2. Which keyword is used to create an object in Java?
A) this
B) var
C) class
D) new
  • 3. What is a class in object-oriented programming?
A) A function in JavaScript
B) Blueprint for creating objects
C) A variable in C++
D) An instance of an object
  • 4. What is polymorphism in object-oriented programming?
A) Hiding implementation details
B) Extending the functionality of a parent class
C) Ability for objects of different classes to be treated as objects of a common superclass
D) Creating objects from classes
  • 5. What is encapsulation in object-oriented programming?
A) Overriding parent class methods
B) Inheriting properties from a parent class
C) Binding together the data and the methods that operate on the data
D) Creating multiple instances of an object
  • 6. What is a constructor in object-oriented programming?
A) A special method that is automatically called when an object is created
B) A method that returns a value
C) A static method
D) A method used to destroy objects
  • 7. What is the 'super' keyword used for in Java?
A) Accessing a private method
B) Declaring a variable
C) Refers to the superclass of a class, used to call methods from the superclass
D) Implementing an interface
  • 8. What is method overloading in object-oriented programming?
A) Creating new methods in a subclass
B) Overriding a method from a superclass
C) Hiding the implementation details of a method
D) Having multiple methods in a class with the same name but different parameters
  • 9. What is data abstraction in object-oriented programming?
A) Hiding the implementation details while showing only the necessary details of an object
B) Overriding methods from a parent class
C) Creating multiple objects from a class
D) Accessing private class members
  • 10. What is a public access modifier in object-oriented programming?
A) Allows for class extension
B) Allows a class, method, or field to be accessed by any other code in the same package or another package
C) Restricts access to within the same class only
D) Hides the object details
  • 11. What is the 'final' keyword used for in Java?
A) Prevents modification of the class, method, or variable
B) Allows multiple inheritance
C) Enables dynamic method binding
D) Forces method overriding
  • 12. Which design principle states that classes should be open for extension but closed for modification?
A) Liskov Substitution Principle
B) Single Responsibility Principle
C) Open/Closed Principle
D) Interface Segregation Principle
  • 13. Which access modifier allows a class to be accessed by any other class?
A) Public
B) Private
C) Default
D) Protected
  • 14. Which keyword is used to inherit a class in Java?
A) super
B) implements
C) this
D) extends
  • 15. Which feature allows a class to have multiple methods with the same name but different parameters?
A) Overriding
B) Overloading
C) Encapsulation
D) Inheritance
  • 16. Which feature allows the same method to be used for different types of objects?
A) Encapsulation
B) Inheritance
C) Polymorphism
D) Abstraction
  • 17. What is the purpose of method overriding in object-oriented programming?
A) To create new methods in a subclass
B) To provide a specific implementation of a method that is already provided by its superclass
C) To have multiple methods with the same name in a class
D) To hide the implementation details of a method
  • 18. Which principle is violated if a subclass cannot be substituted for its superclass?
A) Single Responsibility Principle
B) Liskov Substitution Principle
C) Open/Closed Principle
D) Dependency Inversion Principle
  • 19. A method that has the same name as the class it is defined in is known as a:
A) Constructor
B) Mutator method
C) Destructor
D) Accessor method
  • 20. Which keyword is used to prevent method overriding in Java?
A) final
B) public
C) static
D) abstract
  • 21. Which keyword is used to refer to the current object in Java?
A) new
B) this
C) extends
D) super
  • 22. Which term is used to describe the act of restricting the way subclasses can modify a superclass?
A) Overloading
B) Overriding
C) Overpassing
D) Override
  • 23. Which term describes the ability to create new classes based on existing classes?
A) Encapsulation
B) Abstraction
C) Inheritance
D) Polymorphism
  • 24. Which design principle suggests that a class should have only one reason to change?
A) Interface Segregation Principle
B) Liskov Substitution Principle
C) Open/Closed Principle
D) Single Responsibility Principle
  • 25. Which of the following allows for multiple inheritance in C++?
A) Virtual Inheritance
B) Polymorphism
C) Interfaces
D) Abstract Classes
  • 26. What does the acronym 'DRY' stand for in the context of object-oriented programming?
A) Data Representation Year
B) Do Repeat Yourself
C) Don't Repeat Yourself
D) Dynamic Reuse Yard
  • 27. Which relationship represents a situation where one class is dependent on another class?
A) Inheritance
B) Dependency
C) Composition
D) Aggregation
  • 28. Which type of relationship reflects a 'has-a' relationship between classes?
A) Dependency
B) Composition
C) Aggregation
D) Inheritance
Created with That Quiz — where test making and test taking are made easy for math and other subject areas.