DEV Community

Deva I
Deva I

Posted on

Object oriented programming(OOP) in Java

What is object oriented programming :

Object-Oriented Programming (OOP) is a programming paradigm that organizes software around objects rather than functions and logic.

In simple words object-oriented programming is about creating objects that contain both data and methods.

OOP is faster and easier to execute.
OOP provides a clear structure for the programs.
Improves code reusability.
Enhances maintainability and scalability.
Makes programs easier to understand and manage.
Closely models real-world entities.

Concepts of Object-Oriented Programming (OOP)

Class- A blueprint or template for creating objects.

Object- An instance of class.

Inheritence- Reuse code from existing classes.

polymorphism- Allows the same method to behave differently.

Encapsulation- Protects data from direct access.

Abstraction- Hides unnecesssary details.

Class

A class is a blueprint or template used to create objects. It defines the properties (data) and behaviors (methods) that objects will have.

=> Contains data members and methods.
=> Does not occupy memory until an object is created.

EXAMPLE : A Car represents a class (blueprint), while BMW, Mercedes, and Audi represent objects (instances) created from that class.

Object

An object is an instance of a class. It represents a real-world entity and can access the properties and methods defined in the class.

=>Occupies memory when created.
=>Used to access class members.

Inheritence

Inheritance allows one class to acquire the properties and methods of another class.

=>Establishes parent-child relationship.
=>Supports method overriding.

EXAMPLE : Dog, Cat, Cow can be Derived Class of Animal.

Polymorphism
Encapsulation
Abstraction (To Be Discussed)

Top comments (0)