The equals() method returns a boolean value indicating whether two objects are equal. Using the above code, will the two BankAccount objects be equal? Explain why or why not.

What will be an ideal response?


The equals() method considers two objects of the same class to be equal only if they have the same hash code; in other words, they are equal only if one is a reference to the other. The two BankAccount objects are equal because their account numbers and balances match. Because the equals() method is part of the BankAccount class, and because equals() is a nonstatic method, the object that calls the method is held by the this reference within the method. acct1 becomes the this reference in the equals() method, so the fields acctNum and balance refer to acct1 object values. In the CompareAccounts application, acct2 is the argument to the equals() method; so within the equals() method, acct2 becomes secondAcct, and secondAcct.acctNum and secondAcct.balance refer to acct2's values.

Computer Science & Information Technology

You might also like to view...

A ________ is a program that defines how form data should be handled by a Web server

Fill in the blank(s) with correct word

Computer Science & Information Technology

Pressing the ____ key deletes one character at a time to the right of the insertion point.

A. CTRL B. BACKSPACE C. SHIFT D. DELETE

Computer Science & Information Technology

CPUs that run faster generally require more energy and generate more heat.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What is the default color of a drop shadow?

A. Dark gray B. Black C. Light gray D. White

Computer Science & Information Technology