A class defined by the programmer is used exactly in the same way as a predefined class (e.g., String).
public class ClientClassPerson { public static void main(String[] args) { Person p1; p1 = new Person(); p1.setResidence("Roma"); System.out.println(p1.getResidence()); } }
The class ClientClassPerson is a client of the class Person, since it makes use of such a class. The client defines the method main (the method of the program that is called first) in which:
Note: The class ClientClassPerson must be saved in a file called ClientClassPerson.java. The file must be placed in the same directory as the file containing the class Person, in order to avoid problems during the compilation or the execution of the class ClientClassPerson. We could overcome this limitation by making use of so called packages, but we will not deal with packages in this course.