One of the conditions of the problem: In the Cat class, add the public static variable cats (ArrayList<Cat>) public . I understand it like this:

 public static int cats; 

Q: What is (ArrayList<Cat>) ?

  • one
    Read about generic. Here is the official documentation docs.oracle.com/javase/tutorial/java/generics/index.html - Mikhail Vaysman
  • Please state in detail in the question description the condition of the problem. Where did you get the ArrayList <Cat>? - Mikhail Rebrov
  • If I were given such a task with such a condition, then I would understand it like this: public static ArrayList<Cat> cats = new ArrayList<>(); . Or so public static List<Cat> cats = new ArrayList<>(); What does int do with anything? - Sergey
  • one
    @Mikhail Rebrov, here’s the actual condition of the problem: / * Static cats 1. In the Cat class, add public the static variable cats (ArrayList <Cat>). 2. Let every time a cat (a new Cat object) is created, this new cat is added to the cats variable. Create 10 Cat objects. 3. The printCats method should display all cats on the screen. It is necessary to use the variable cats. * / - SergioBerluskony

2 answers 2

 ArrayList<Cat> - это список, в котором лежат объекты класса Cat 

ArrayList is one of the implementations of the List interface (list) which is based on a regular array.

There are other implementations of this interface: for example, LinkedList (Linked List).

Learn more about the topic of collections in Java.

About generics you wrote in the comments.

    Imagine an array that behaves like an object. That is, it has methods that allow you to add / remove something in yourself. This is such a tricky array called ArrayList .
    So that you can add only Сat to an ArrayList , you limit yourself:

     ArrayList<Сat> 

    With such a construction, it is impossible to put anything in ArrayList except for instances of class Сat .
    For example, restrict String :

     ArrayList<String> 

    Nothing but rows put.