Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Cat {
- // instance variables… These are used and visible throughout the class. They are the backbone of our class.
- private int age;
- private String color;
- private String name;
- // constructors… The construction crew…. how to build the perfect cat
- // default Cat
- public Cat() {
- }
- // a better Cat
- public Cat ( int age, String name, String color ) {
- this.age = age;
- this.name = name;
- this.color = color;
- }
- // methods… the things our cat does and the place where changes can be made to our cat or information retrieved
- public int getAge() {
- return age;
- }
- public String getName() {
- return name;
- }
- // Now you make a get color method…
- public String getColor(String color) {
- return color;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setColor(String color){
- this.color = color;
- }
- // Now how about those other behaviors…
- public void eat() {
- System.out.println("Chew, chew, chew" ) ;
- }
- public void drink() {
- System.out.println("Drink, drink, drink" );
- }
- public void talk() {
- System.out.println("Meow");
- }
- public void sleep() {
- System.out.println("Zzzzzzzzzzzzzzzz");
- }
- public void happyBirthday() {
- this.age++;
- System.out.println("Happy Birthday, " + this.name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement