DEV Community

Pavitra Aravind
Pavitra Aravind

Posted on

Sample program using Encapsulation

Input:

class Bank
{
String name;
int loan;
private int interest;

public Bank(String name, int loan, int interest)
{
this.name = name;
this.loan = loan;
this.interest = interest;
}
public static void main(String[] args)
{
Bank SBI = new Bank("Aravind",1000,5);
SBI.receive();

}

private void receive()
{
System.out.println(interest);
}

}

Input:

class Bank2
{
public static void main(String[] args)
{
Bank canara = new Bank("Dev",5000,2);
canara.receive();
}
}

Output:

Image description

Top comments (0)