15 programming trivia questions and answers online spanning object-oriented programming concepts.
1. What is an 'object' in OOP?
💡 An object is a specific instance created from a class, with its own data and behavior.
2. What is a 'static method' in OOP?
💡 A static method belongs to the class itself rather than any particular instance of the class.
3. What is a 'class' in OOP?
💡 A class serves as a blueprint that defines the properties and methods for creating objects.
4. What is 'method overloading'?
💡 Method overloading allows multiple methods with the same name but different parameter lists to coexist.
5. What is 'inheritance' in OOP?
💡 Inheritance allows a new class to derive properties and behaviors from an existing parent class.
6. What is 'abstraction' in OOP?
💡 Abstraction hides complex implementation details, exposing only the necessary functionality to the user.
7. What is 'encapsulation' in object-oriented programming?
💡 Encapsulation bundles an object's data and the methods that operate on it into a single unit, or class.
8. What does 'this' or 'self' typically refer to in OOP languages?
💡 'this' or 'self' refers to the current instance of the object within a class method.
9. What does 'method overriding' mean?
💡 Method overriding allows a subclass to provide its own specific implementation of a method inherited from its parent class.
10. What is a 'constructor' in OOP?
💡 A constructor is a special method automatically called when a new object is created, used to initialize it.
11. What is 'composition' in OOP?
💡 Composition builds complex objects by combining simpler, independent objects as components.
12. What does 'private' access modifier typically restrict?
💡 The 'private' access modifier restricts access to a class member so it can only be used within that class.
13. What is the difference between an abstract class and an interface?
💡 Traditionally, abstract classes can contain both implemented and unimplemented methods, while interfaces only declare method signatures.
14. What is an 'interface' in OOP?
💡 An interface defines a contract of methods that implementing classes must provide, without specifying how.
15. What is 'polymorphism' in OOP?
💡 Polymorphism allows objects of different classes to be treated through a shared interface, taking different forms.