Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Encapsulation {
- // variables
- private int age;
- // default constructor
- public Encapsulation() {
- }
- // encapsulation
- public void setAge (int newAge) {
- if (newAge < 0) {
- System.out.println("Invalid age");
- } else {
- age = newAge;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement