University of Toronto - Fall 2000
Department of Computer Science

Week 6 - Types

Objects vs Primitive Data Types

Primitive Data Type

public class PrimType {
	public static void main (String[] args) {
		int i;
		int j;
		i = 2;
		j = 3;
		System.out.println (i);
		i = j;			// copies value of j into i
		System.out.println (i);
		j = 4;
		System.out.println (i);
	}
}

Draw the memory model for the above example.

Class Data Type

class Ex {
	public int field;
}
public class ClassType {
	public static void main (String[] args) {
		Ex e = new Ex();
		Ex f = new Ex();
		e.field = 2;
		f.field = 3;
		System.out.println (e.field);
		e = f;			// copies reference in f into e
		System.out.println (e.field);
		f.field = 4;
		System.out.println (e.field);
	}
}

Draw the memory model for the above example.