The Blueprint (Class Definition)
Class = Blueprint
public class Pet
Fields (what data each Pet holds)
private
String
name
private
String
species
private
int
age
Constructor (how to build a Pet)
public Pet(String name, String species, int age) {
this.name = name;
this.species = species;
this.age = age;
}
this.name = name;
this.species = species;
this.age = age;
}
Methods (what a Pet can do)
String getName()
void setName(String name)
String getSpecies()
void setSpecies(String species)
int getAge()
void setAge(int age)
new creates a fresh object in memory from this blueprint
Tip: The class itself doesn't hold data. It only describes what data an object will have. Each object gets its own separate copy.
Create Objects (Instances)
No objects created yet. Use the form above to create a Pet.
Modify Selected Object
Use a setter to change one value. Notice: only this object changes. Others stay the same.