Object-Oriented Programming or OOPs refers to a style that uses objects in programming. Object-oriented programming aims to implement real-world entities like object,class,inheritance, polymorphism ,abstraction,encapsulation etc in programming. Object oriented programming brings together data and its behavior(methods) in a single location(object) .It simplifies software development and maintenance process.
Java supports the following fundamental concepts −
We will discuss the above concepts one by one:
An object is an instance of a class.Objects have states and behaviors. Example: A pen or marker has states – color, name, weight as well as behaviors – writing, drawing, coloring etc.
Collection of objects is called class.A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports.The class is a group of similar entities.It is only a logical entity.For example marker is a class while Reynolds,cello etc are objects.
Methods represent the functionality or behaviour of any object.For example pen has the functionality of writing or drawing.So these functionalities or behaviors are represented by methods in java.
Inheritance is an OOPS concept in which one object acquires the properties and behaviors of the parent object. That means child class inherits the property of parent class. Inheritance makes the software development easy as we have the facility to acquire properties from parent class writing much code.
Polymorphism means the ability to have multiple forms at different places. For example the word orange is the fruit and also it is a color.So according to the condition we use it in different context.
Abstraction means showing only the functionality about how it works and hiding the internal details.For example we know how to ride a bike but there are some internal things which are actually responsible to ride a bike such as combustion,torque etc. but the rider has to know only the knowledge of gear,accelerator and clutch to ride a bike.
Wrapping up of a data in a single unit is called encapsulation.Encapsulation is achieved when all the private data members are hidden from other classes and they can only be accessed via public methods.Java bean classes are the fully encapsulated classes. Encapsulation is also known as data hiding in java.For example our bank account details are kept private and when we login only then we are allowed to make transactions and any changes,so other person can not know our balance and other details.So this information is confined to us only.