publicclassCat{//attributes
privateStringname;privateintlives= 9;//methods
publicCat(Stringname){this.name=name;}publicvoidspeak(){System.out.println("meow!!");}// main method
publicstaticvoidmain(String[]args){CatmyCat=newCat("Ollie");// creates a new cat object
myCat.speak();//calls the cat object's method
}}
You can see that there are two attributes (name and lives) and three methods (the constructor, speak and main).
The main method already creates a Cat object and gets it to seak
๐ปAdd a method that lets the cat introduce itself. It should print a greeting out to the console, including the cat’s name.
๐ปTest your new method by calling it in the main method.
You can see that the cat starts out with 9 lives. ๐ปAdd a loop to the main method that can kill the cat.