1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sashaice [31]
2 years ago
13

Assume that class BankAccount exists, and that it has a constructor that sets the private field balance, and that setBalance and

getBalance are defined by class BankAccount and set and get double values. Then what is the output of the following code:________.
a. 600.0
b. 0.0
c. 300.0
d. null
e. an error will result
Computers and Technology
1 answer:
Ainat [17]2 years ago
4 0
<h2>Question:</h2>

Assume that class BankAccount exists, and that it has a constructor that sets the private field balance, and that setBalance and getBalance are defined by class BankAccount and set and get double values.

Then what is the output of the following code?

BankAccount b1 = new BankAccount(600.0);

BankAccount b2 = b1;

b1.setBalance(300.0);

System.out.println(b2.getBalance() );

<h2>Answer:</h2>

300.0

<h2>Explanation:</h2>

The given snippet of code is as follows:

=======================================

BankAccount b1 = new BankAccount(600.0);

BankAccount b2 = b1;

b1.setBalance(300.0);

System.out.println(b2.getBalance() );

=======================================

<u><em>Line 1</em></u>: An object b1 of the BankAccount class is created which sets the value of its <em>balance </em> to 600.0

<u><em>Line 2</em></u>: A second object, <em>b2</em>, is created referencing or pointing to the first object, <em>b1 </em>in memory. It could also be interpreted to mean that a second object <em>b2</em> is created from the exact copy of the first object, b1. This is called <em>object cloning</em>. This by implication means that all the fields (including the contents of the fields) of the first object b1, are copied to b2 which also means that when there's a change in b1, an update is made to b2 also. If a change is made to b2, b1 also gets updated.

<u><em>Line 3</em></u>: Object <em>b1</em> is updated by setting the value of its <em>balance</em> field to 300.0 using the setBalance() method. This will also update the same field for the second object <em>b2.</em>

<em />

<u><em>Line 4</em></u>: The value of the <em>balance</em> field of object b2 is being printed to the console. Since the value has been updated in line 3 when that of b1 was updated, <em>300.0</em> will be printed to the console.

<em />

<em />

You might be interested in
8.4 Lesson Practice <br> edhesive quiz
kow [346]

Answer:

1. 5

2. Because they let us quickly process the contents of an array, which have many values.

Explanation:

8 0
3 years ago
An open intersection is one that
alekssr [168]

 open intersection is one without traffic control signs or signals. When you enter one, you must yield the right-of-way if: A vehicle is already in the intersection. You enter or cross a state highway from a secondary road. hope this helped


4 0
3 years ago
Read 2 more answers
The amount of data that can be stored on a disk depends in part on_____.
MariettaO [177]
To what it seems like, it’s d
8 0
2 years ago
How can u refer to additional information while giving a presentation
yawa3891 [41]

Answer:

There are various ways: Handing out papers/fliers to people, or presenting slides.

7 0
3 years ago
10
Dmitrij [34]

Answer:

i need more \\

Explanation:

Chemical cold packs should be used for bone and joint injuries because they are generally colder than ice and stay cold longer.

A.  

True

B.  

False

Reset

4 0
2 years ago
Other questions:
  • Most large organizations store data through a strategy called a(n) ________ to promote efficient and safe use of data across the
    11·1 answer
  • Mario makes a check payable to "cash," intending to withdraw money from his bank. Kirby takes the check from Mario's notebook an
    10·2 answers
  • What food does swiss eat on christmas?
    10·1 answer
  • What are the two most popular applications of theInternet?
    7·1 answer
  • You are configuring NIC teaming on a server with two network adapters. You chose Switch Independent Mode. You now must choose be
    15·1 answer
  • Raul is a 13-year-old teenager interested in taking up photography as a new hobby. His dad wants to buy him a camera for his bir
    13·1 answer
  • Which finger is used to press SHIFT key while typing!
    14·2 answers
  • Can you help me with this question please ​
    13·1 answer
  • How can structure of a table change in sql. What general types of changes are possible
    8·1 answer
  • __________ are very simple devices that connect network components, sending a packet of data to all other connected devices.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!