Font Awesome Icons

Tutorial

OOPS Concept in Java

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 −

 
  1. Object

  2. Class

  3. Method

  4. Inheritance

  5. Polymorphism

  6. Abstraction

  7. Encapsulation

 

 We will discuss the above concepts one by one:

 
 

1)Object

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.

 

 2)Class

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.

 

3)Method

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.

 

4)Inheritance

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.

 

5)Polymorphism

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.

 

6)Abstraction

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.

 

7)Encapsulation

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.