Problem

4/6

Create a link

Theory Click to read/hide

The lessons so far have discussed creating classes, which are templates for creating objects. In the same lesson, the process of creating and using the objects themselves will be described.

Links
In the Java language, a variable can never store an object. Instead, Java has references that point to the location of an object in memory.
The syntax for creating a variable of type object reference is as follows:
<Class name> <variable name>;
It is worth noting that we immediately indicate the class whose objects will be referenced.

Example: a variable named "b" pointing to the Book class:

Book b;

In the same way, you can create class fields (you can add an access modifier there). You can create arrays of references and return them from methods. Example:

public class Libary {
  public Book[] books;
  public Book findBookWithName(String name) {
//code that finds the right book
  }
};


Conclusion: in many ways, you can work with references in the same way as with variables of other elementary types (int, long, double...).

Problem

Create a link a of type Dog.