Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public class Cat {
  2.  
  3. private String name;
  4. private int age;
  5.  
  6. public Cat() {
  7.  
  8. }
  9.  
  10. public Cat(String name, int age) {
  11. this.name = name;
  12. this.age = age;
  13. }
  14.  
  15. public String getName() {
  16. return name;
  17. }
  18.  
  19. public void setName(String name) {
  20. this.name = name;
  21. }
  22.  
  23. public int getAge() {
  24. return age;
  25. }
  26.  
  27. public void setAge(int age) {
  28. this.age = age;
  29. }
  30.  
  31. public static void main(String[] args) {
  32. Cat Filemon = new Cat();
  33. String cat_name;
  34. int cat_age;
  35.  
  36. Filemon.setName("Filemon");
  37. Filemon.setAge(21);
  38. cat_name = Filemon.getName();
  39. cat_age = Filemon.getAge();
  40.  
  41. System.out.println("Cat has name " + cat_name + " and is " + cat_age + " years old.");
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement