Self-help exercises: evaluating new-expressions
As mentioned in the lecture, evaluation of a new expression like
new Animal()
is a two-step process:
- Create (or draw) a new manila folder (object) of class Animal;
- Yield as the value of the new-expression the name (on the tab) of the new object.
It is important that you (1) understand this two-step process and (2) can carry it out yourself. The best way to learn this is to evaluate a new-expression ourself, carrying out the two steps. Do not procrastinate; do the two exercises below immediately, before going on to the next lecture.
1. Below are three assignments that refer to class Animal and class Patient (see the objects given below for the format), used in a previous lecture. First, draw variables p and q on a piece of paper, with value null in them. Then, execute these three assignments, one after the other, evaluating any new-expressions that have to be evaluated and storing the results in the indicated variables. Here is the answer.
p= new Animal();
q= new Patient();
p= new Animal();