Question 3 Assume the method below has been added to the BankAccount class. publ
ID: 3846088 • Letter: Q
Question
Question 3
Assume the method below has been added to the BankAccount class.
public void transfer(BankAccount source, double amount)
{
balance = balance + amount;
source.balance = source.balance – amount;
}
What will be output from the following statements that use the revised BankAccount class?
BankAccount first = new BankAccount(100.0);
BankAccount second = new BankAccount(300.0);
first.transfer(second, 50.0);
System.out.println(first.getBalance() + " " + second.getBalance());
Question 4
Write the constructor header for a Player class that accepts the player's name as its only parameter (called "name").
Explanation / Answer
Question 3 :
first.getBalance() => 150.0
second.getBalance() => 250.0
Question 4 :
public class Player
{
public Player(String name) //constructor that accepts only one argument as name
{
System.out.println(name); //just printing that name
}
public static void main(String args[])
{
Player p = new Player("sasi"); //sending name to parameterised constructor
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.