X hits on this document

144 views

0 shares

0 downloads

0 comments

41 / 46

© S. Uchitel, 2004

41

Comparison

Careful with the comparison ( “==”) operator:

Primitive types: compares values

Car myCar = new Car("blue", "Fiesta", 45); Car yourCar = new Car("blue", "Fiesta", 45);

Car ourCar = myCar; (myCar == yourCar)

(myCar == ourCar)

int a = 4; b = 4; c = 3;

(a == b)

(a == c)

(a == 4)

// evaluates to true

// evaluates to false

// evaluates to true

// evaluates to false

// evaluates to true

Reference types: compares references

Classes may provide an equals method for comparing object content: myCar.equals(yourCar)

Document info
Document views144
Page views144
Page last viewedWed Jan 18 15:37:12 UTC 2017
Pages46
Paragraphs816
Words2901

Comments