There are three main features of OOPS:

  1. Encapsulation
  2. Inheritance
  3. Polymorphism

Wrapping of data and methods into a single unit is known as Encapsulation. It provides the security that keeps data and methods safe from unwanted changes. Class is the example of encapsulation which binds fields and members into a single unit.

Learn Java

To get encapsulation using

  • Declare the variables of a class as private.
  • Provides public getter and setter methods to change and sight the variables values.


public class Addition{
private int sum;
public void settotal(int a, int b){
sum = a + b;
public void gettotal()
System.out.println("Addition of two numbers:" +sum );
public static void main(String []args){
Addition add = new Addition ();
add.settotal(10, 20);

Addition of two numbers:30
Learn more about Cross-Platform Mobile Technology for Android and iOS using Java in this insightful blog now!

Recommended Videos

Course Schedule

Name Date
Python Course 2021-04-24 2021-04-18
(Sat-Sun) Weekend batch
View Details
Python Course 2021-05-01 2021-04-25
(Sat-Sun) Weekend batch
View Details
Python Course 2021-05-08 2021-05-02
(Sat-Sun) Weekend batch
View Details

Leave a Reply

Your email address will not be published. Required fields are marked *