Writing Classes Lesson
College Board Lessons
public class Cow {
String sound = "moo";
String type;
int numMilkings;
public Cow(String cowType, String cowSound) {
this.type = cowType;
this.sound = cowSound;
this.numMilkings = 0;
}
public String getType() {
return this.type;
}
public int getNumMilkings() {
return this.numMilkings;
}
public String getSound() {
return this.sound;
}
public void milkCow() {
this.numMilkings++;
}
}
public class CowDriver{
public static void main(String[] args) {
Cow myCow = new Cow("holstein", "moo");
System.out.println(myCow.getType());
}
}
CowDriver.main(null);