DEV Community

Saravanan
Saravanan

Posted on

1

Day-5 Example for Encapsulation

public class Friend1
{
String name;
long mobileNo; 
private int atmPin; 

public Friend1(String name, long mobileNo, int atmPin)
{
this.name = name; 
this.mobileNo = mobileNo; 
this.atmPin = atmPin; 
}

public static void main(String[] args)
{
Friend1 f1 = new Friend1("Kavin", 1234, 1111);
f1.withdraw();

}
private void withdraw()
{
System.out.println(atmPin);
}
public void tour()
{
System.out.println("Going for a ride");
}

public void publish_results()
{
System.out.println("Pass with good marks ");
}




}
Enter fullscreen mode Exit fullscreen mode
class Friend2
{

public static void main(String[] args)
{

Friend1 ff = new Friend1("Arul",3434,2323);
ff.tour();
ff.withdraw();
}

}
Enter fullscreen mode Exit fullscreen mode

output:

Image description

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay