Skip to content

Instantly share code, notes, and snippets.

@Dean110
Created January 25, 2021 23:11
Show Gist options
  • Save Dean110/0f2a563aa3e23f809f6fdfe1cb43db70 to your computer and use it in GitHub Desktop.
Save Dean110/0f2a563aa3e23f809f6fdfe1cb43db70 to your computer and use it in GitHub Desktop.
Class demonstration from lecture
package org.wecancodeit;
public class Cat {
private String name;
private String furColor;
private int age;
private int lives;
public Cat(String name, String furColor, int age, int lives) {
this.name = name;
this.furColor = furColor;
this.age = age;
this.lives = lives;
}
public void greeting() {
System.out.println("My name is " + name + "! I have "
+ furColor + " fur." +
"I'm " + age + " years old, and I have "
+ lives + " lives left!");
}
public String getName(){
return name;
}
public String getFurColor() {
return furColor;
}
public int getAge() {
return age;
}
public int getLives() {
return lives;
}
}
package org.wecancodeit;
public class Main {
static Cat annoying = new Cat("Annoying", "blue", 4, 9);
static Cat furBall = new Cat("Furry", "gray", 3, 3);
public static void main(String[] args) {
System.out.println("Tell us about yourself.");
annoying.greeting();
furBall.greeting();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment