Object Oriented Programming - acheung1/JavaTutorial GitHub Wiki

Better explanation

What is object oriented programming?

  • Programming paradigm that involves around the concepts of objects.
  • A class can be thought as a blueprint which objects are created from. It define the state and behavior of object that are instantiated from this class.
  • Objects can be think as models to real life objects. An object is defined by its state and behavior.

The four main concepts of OOP

Inheritance

  • Parent and child classes. A child class inherits state and behavior from its parent class.

Polymorphism

A child class can have methods that override parent methods.

  • Overriding: creating a method in child class that has the same signature(method name and parameters) as with the parent class version.
  • Overloading: creating a method in child class that has different signature than the parent class version.

Abstraction

  • Hiding implementation and showing only functionality
  • Achieve through abstract class or interface

Encapsulation

  • Data of the object is hidden inside the object itself through the private keyword.
  • Implement getter/setter if you want access you to your private instance variables
  • Adds security ``