Challenge Challenge


I warned you that there would be a lot of practice.

Now your task is to do the opposite. In the main method, there is already code for creating multiple objects of the Cat class, initializing their fields, and calling a method. Your task is to write the Cat class so that it meows when the meooow() method is called. You can also create a translator from cat language to English, as was done in the example with the Dog class. But that is optional.


  1. 1. In the Cat class, create fields named name, age, and color. Keep in mind that name and color should have the type String, while age should have the type double;
  2. 2. Next, in the Cat class, create a method with a return type of void that will display "Meow" on the screen;
  3. 3. Optionally, you can add the following syntax:
  4. "Meow (that means 'Hey, my name is " + name + "!')"

package com.example;

class Cat {
    String name;
    double age;
    String color;

    void meooow() {
        System.out.println("Meow (that means 'Hey, my name is " + name + "!')");

public class Main {
    public static void main(String[] args) {
        Cat Michael = new Cat(); = "Mikey";
        Michael.age = 0.5;
        Michael.color = "Black";
        Cat Garfield = new Cat(); = "Garfield";
        Garfield.age = 4.7;
        Garfield.color = "Red";

Everything was clear?

Section 4. Chapter 5