Skip to content

Instantly share code, notes, and snippets.

@edolopez
Created March 23, 2014 17:00
Show Gist options
  • Save edolopez/9726086 to your computer and use it in GitHub Desktop.
Save edolopez/9726086 to your computer and use it in GitHub Desktop.
Puppy class and PuppyTest (with the main method), an example of Objects
public class Puppy {
// Instance Variables
int age;
String color;
String breed;
double weight;
String name;
public Puppy() {
name = "Default";
weight = 20.0;
age = 0;
color = "Red";
}
public Puppy(int puppyAge, String puppyBreed, String puppyName) {
name = puppyName;
age = puppyAge;
breed = puppyBreed;
}
public int getAge() {
return age;
}
public void setAge(int puppyAge) {
age = puppyAge;
}
public String getColor() {
return color;
}
public void setColor(String puppyColor) {
color = puppyColor;
}
public void bark() {
System.out.println("GUAF, such code");
}
}
// http://www.tutorialspoint.com/java/java_object_classes.htm
import java.util.Scanner;
public class PuppyTest {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
Puppy dog = new Puppy();
dog.bark();
System.out.println(dog.getColor());
Puppy doge = new Puppy(2, "shiba", "Charles");
doge.setColor("Yellow");
System.out.println(doge.getColor());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment