One Pager Cheat Sheet
- This lesson covers the four fundamental properties of
Object-Oriented Programming
and explains howEncapsulation
,Abstraction
,Inheritance
, andPolymorphism
help create an OOP language such as Java, C++, Python, or JavaScript, and the conditions for it to become a Pure OOP Language. - Encapsulation dictates that all data related to an object should be
inside
the object, meaning that an object cannot access properties if they areoutside
itself. - Abstraction in OOP is utilizing special keywords to prevent anyone from calling certain functions from outside of the class and letting users of the class only use the methods that are
public
and needed to use the class. - Inheritance allows code to be reused by creating a parent-child relationship between two classes, where one class can access all the properties and methods of the other, enabling objects to be created from a more specific type of the parent class.
- Java's keyword
extends
allows programmers to create more specific classes by inheriting properties and methods from a parent class, while adding or overriding existing methods and properties as needed. - The last of the four fundamental properties of OOP is Polymorphism, which enables objects to act like their parent types, as well as other types (e.g. interfaces).
Polymorphism
allows us to avoid writing cumbersome code for our main program.- We can use the concept of
Polymorphism
to create an array of shapes, where each input from the user is an instance of the corresponding class from the array. - We can use polymorphism to more concisely apply a single command to multiple types of objects, such as the
getArea()
method, with thefor
loop in this example. - The code snippet demonstrates polymorphism, allowing an object of type
A
to refer to a different typeB
, and use the corresponding implementation of the same method when called. - You have learned the fundamentals of
Object-Oriented Programming (OOP)
, and in the next lesson, you will explore moreadvanced concepts
such as constructors, destructors, virtual methods, and abstract classes.