OOP Flashcards
Why do we need OOP
OOP helps us to think in terms of real world objects. For example you can Have a person and store his name age and address simply in the object.
What are the important pillars in OOP
Abstraction which is to show only what is necessary. Polymorphism which is where the object acts differently under different conditions, for example if you had an employee who changed from a user to an admin. Inheritance which is where you have a parent child relationship where you have something in common in the parent and the child can inherit it, for example you could have a class cars that has a property of colors and there child could be a type of car which as well would then need to have colors also. Encapsulation which means to hide complexity.
What is a class and an object
A class is a blueprint or a type which to create you need to make an instance of a class which will be an object and will have properties and methods.
Difference between Abstraction and Encapsulation
Abstraction happens during the design phase and decide what has to be shown public where as during the execution phase the developer uses encapsulation to implement the thought process of abstraction.
What is inheritance
A way to pass down properties and methods in classes from parent to child. (extend) keyword to become a child of parent
What is overloading
In the same class you can have the same method names with different parameters.
What is overriding
A way to change the logic of a function from a parent that was passed to a child. (super) keyword to allow overriding of parent function but not replacing.
What is polymorphism
An ability of an object to act differently under different conditions. Polymorphism cannot be implemented without inheritance.
What is polymorphism
An ability of an object to act differently under different conditions. Polymorphism cannot be implemented without inheritance.
Why do you need abstract classes
It is a half defined parent class where some methods are defined and others are left undefined to be handled by the child classes. You cannot create instances of an abstract class.
What is encapsulation
Storing all variables and functions inside of an object to keep things organized. Benefits would be function have less parameters due to properties being nested in object and better than procedural programming where you have a bunch of function everywhere and can cause problems when having to change things.
What is abstraction
Through the process of abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency.