Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. public class Encapsulation {
  2.  
  3. // variables
  4. private int age;
  5.  
  6. // default constructor
  7. public Encapsulation() {
  8.  
  9. }
  10.  
  11. // encapsulation
  12. public void setAge (int newAge) {
  13.  
  14. if (newAge < 0) {
  15. System.out.println("Invalid age");
  16. } else {
  17. age = newAge;
  18. }
  19.  
  20. }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement