- Object-Oriented Programming (or OOP) is a JAVA paradigm that organizes software design around data, or objects rather than functions and logic.
Classes:
To create an object a Class
is required.
- A class is a blueprint for creating objects. It defines the properties and behaviors that objects of a certain class can have.
- Classes specify what data an object can have (attributes) and what it can do (methods).
- A class bundles its attributes and methods through encapsulation (1. Encapsulation), protecting the data.
Objects:
Objects are any real world entity (like car, bike, dog, ATM, etc.) which has two things:
- Properties or State
- Behavior or Function
Example
Dog is an object:
- Properties like: Age, Breed, Color, etc.
- Behaviors like: Bark, Sleep, Eat, etc.
An object is an instance of a class. Each object has its own set of fields defined by the class, but the methods are shared among all objects of the class.
Creating Objects