Today, I'm going to explain OOPS concepts.
OOPS Concepts are: Inheritance, Encapsulation, Polymorphism, Abstraction, Object, Class
Lets dig into each one of them one-by-one.
Inheritance:
Process of acquiring the base class properties into the derived class is called inheritance.
e.g. , We have a class CustomList which implements List interface in java. That means, now CustomList will behave like actual Java List. It will be having all the properties of List class in java.
So, if we extend some class in java to acquire it's properties, then it saves time and reduces code size.
pros of using Inheritance:
Abstraction:
Class:
A class is a user defined blueprint or prototype from which objects are created.
A class can include Class name, Class body, interfaces, super classes etc.
Object:
It is a basic unit of OOP and represents real life entities.
An object consists of State, behavior and Identity.
OOPS Concepts are: Inheritance, Encapsulation, Polymorphism, Abstraction, Object, Class
Lets dig into each one of them one-by-one.
Inheritance:
Process of acquiring the base class properties into the derived class is called inheritance.
e.g. , We have a class CustomList which implements List interface in java. That means, now CustomList will behave like actual Java List. It will be having all the properties of List class in java.
So, if we extend some class in java to acquire it's properties, then it saves time and reduces code size.
pros of using Inheritance:
- Saves time and reduces code size.
- Let the derived class act like base class.
Note: Acquiring properties doesn't mean to acquire methods of base class.
Encapsulation:
Process of wrapping up of data and methods into a single unit is called encapsulation.
e.g., We have a class in which we have 2 variables and getter-setter methods for these variables.
So, here, variables are the data and getters-setters are functions which are wrapped into one entity called class.
pros of using Encapsulation:
- Provides data hiding. Programmer can hide the inner classes and let users to access only desired code.
Describing the overview
without going into details is termed as abstraction.
Abstraction allows the
developer to separate objects so that they can work on different levels of
detail more easily.
e.g., if you are defining an object-oriented
application to model a zoo, you can define a base class "animal",
then derive "reptile", "mammal", "bird", and "fish"
from it.
The "animal" class defines the attributes and
actions of all animals. Each of the derived classes refine those
attributes and actions to a finer level of detail.
It can also be defined
as the concept that an object totally separates its interface from its
implementation.
Polymorphism:
Polymorphism is the capability of a method to do different things based
on the object that it is acting upon.
OR
It is the ability of a method to take multiple forms while having same name.
It has two types in java: Method Overloading and Method Overriding.Class:
A class is a user defined blueprint or prototype from which objects are created.
A class can include Class name, Class body, interfaces, super classes etc.
Object:
It is a basic unit of OOP and represents real life entities.
An object consists of State, behavior and Identity.
No comments:
Post a Comment