Self help exercise- evaluating new expressions

Self help exercise- evaluating new expressions - objects...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Self-help exercises: evaluating new-expressions As mentioned in the lecture, evaluation of a new expression like new Animal() is a two-step process: 1. Create (or draw) a new manila folder (object) of class Animal; 2. Yield as 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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(); Solution: There are two variables, p and q, initially containing null. After execution of these assignments: p= new Animal(); q= new Patient(); p= new Animal(); the variables and created objects look like this:...
View Full Document

Page1 / 2

Self help exercise- evaluating new expressions - objects...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online