DEV Community

Pavitra Aravind
Pavitra Aravind

Posted on

1

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay