Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

use the above infomation to determine either True or False for the following and

ID: 3594044 • Letter: U

Question

use the above infomation to determine either True or False for the following and briefly explain why

1. course1 == course2

2. course1.equals(course2)

3. course1 == course3

4. course1.equals(course3)

Given the following declarations: public class Course private int num = 0; public Course (int num) Lnum-nNum; } public boolean equals(Object that) return that instanceof Course) & & (this.num(Course)that).num) Course course! Course course2 new Course (450); course! Course course3 = new Course (450);

Explanation / Answer

Answer:

== operator is a reference comparison, so it will check whether both objects point to the same memory location
.equals() evaluates to the comparison of values in the objects

1. course1 == course2 will return true course1 object is assigne to course2 object. so memory location of both is same so it will return true.

2. course1.equals(course2) will return true. equals method will check contents of the objects. so it will return true

3. course1 == course3 will return false . course1  and course3 are two different objects and not pointing ot the same memory location.

4. course1.equals(course3) will return true