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.
What is Abstraction in OOP achieved through?
Abstraction can be achieved through methods that hide internal implementation details and interfaces that define functionalities without specifying how they are implemented.
What are the advantages of Encapsulation in OOP?
Encapsulation promotes data security by restricting direct access and improves code maintainability by keeping functionalities within a well-defined unit (object).
What is Polymorphism beneficial for in OOP?
Polymorphism allows for flexible and dynamic behavior. You can write code that works with different objects without modifying it for each specific class.
What are some challenges of using OOP?
OOP can introduce complexity if overused. Understanding relationships between objects and managing inheritance hierarchies can require careful planning.
What is a constructor in OOP?
A constructor is a special method in a class that is called when an object is created. It’s used to initialize the object’s properties with starting values.
What is the difference between static and non-static methods in OOP?
Non-static methods operate on data specific to an object instance. Static methods are associated with the class itself and can be accessed without creating an object.
What is the role of getters and setters in OOP?
Getters and setters are methods used to control access to an object’s properties. Getters retrieve the property value, while setters modify it while potentially adding validation or security checks.