...
- Fields: The class
Cat
has two fields,name
andage
. Each field has a type, which ensures that we can only store aString
inname
and anint
in age. The wordprivate
before each field indicates that the field can only be accessed from within the classCat
. In Java, by convention most fields are private, and if you want to be able to access them from outside the class, you add getter and setter methods (we will get to these shortly). - Constructors: The class
Cat
has a single constructorpublic Cat(String name, int age){...
}. Constructors are used to create instances of the class. An example of the invoking the constructor can be seen inCatsTheMusical.java
. - Methods:
...