Foundations Flashcards
What does OOP stand for?
Object-Oriented Programming
How does OOP organize code?
By using objects that combine data (properties) and actions (methods).
What are the four pillars of OOP?
Encapsulation, Abstraction, Inheritance, Polymorphism
What is Encapsulation?
Bundles data (properties) and methods that operate on it within an object.
Like a coffee maker - protects internal workings (water level) and controls access (setter methods).
What is Abstraction?
Hides complex details and shows essential functionalities. Like a TV - use turnOn without knowing how the image is displayed.
What is Inheritance?
Reuses code by creating new objects based on existing ones. A bird class inherits from animal (fly()), adding chirp().
What is Polymorphism?
Objects of different classes respond differently to the same method. Animal class with subclasses dog (bark()) and cat (meow()), both having a makeSound() method.
What are Classes and Objects in OOP?
A class is a blueprint that defines the properties and methods of similar objects. An object is an instance of a class, representing a specific entity with its own data and behavior.
What are the benefits of OOP?
OOP promotes code reusability, maintainability, modularity, and data protection by organizing code into objects with well-defined functionalities.
What is a Method in OOP?
A method is a function defined within a class that represents an action or behavior that the object can perform.
What is a Property in OOP?
A property is a characteristic of an object that holds data and can be accessed or modified by methods.
What are the different types of inheritance in OOP?
There are different types of inheritance like single inheritance (one subclass inherits from one superclass), multiple inheritance (subclass inherits from multiple superclasses), and hierarchical inheritance (forming a hierarchy of classes).
What is the difference between public, private, and protected access modifiers in OOP?
Access modifiers control access to an object’s properties and methods. Public allows access from anywhere, private restricts access to the class, and protected allows access from within the class and subclasses.
What is an Interface in OOP?
An interface defines a contract that specifies what methods a class must implement. It promotes loose coupling and enables polymorphism.
What is the difference between a Class and an Instance in OOP?
A class is the blueprint, while an instance (object) is the specific realization of that blueprint with its own data.