implement the \"this\" Reference in Transactions. java public class Transactions
ID: 3815466 • Letter: I
Question
implement the "this" Reference in Transactions. java public class Transactions
public class Transactions
{
public static void main(String[] args)
{
Account acct1 = new Account("Ted Murphy", 72354, 102.56);
Account acct2 = new Account("Jane Smith", 69713, 40.00);
Account acct3 = new Account("Edward Demsey", 93757, 759.32);
acct1.deposit(255.85);
double smithBalance = acct2.deposit(500.00);
System.out.println("Smith balance after deposit: " + smithBalance);
System.out.println("Smith balance after withdrawal: " + acct2.withdraw (430.75, 1.50));
acct1.addInterest();
acct2.addInterest();
acct3.addInterest();
System.out.println();
System.out.println(acct1);
System.out.println(acct2);
System.out.println(acct3);
}
}
Explanation / Answer
public class Transactions
{
public static void main(String[] args)
{
Account acct1 = new Account("Ted Murphy", 72354, 102.56);
Account acct2 = new Account("Jane Smith", 69713, 40.00);
Account acct3 = new Account("Edward Demsey", 93757, 759.32);
acct1.deposit(255.85);
double smithBalance = acct2.deposit(500.00);
System.out.println("Smith balance after deposit: " + smithBalance);
System.out.println("Smith balance after withdrawal: " + acct2.withdraw (430.75, 1.50));
acct1.addInterest();
acct2.addInterest();
acct3.addInterest();
System.out.println();
System.out.println(acct1);
System.out.println(acct2);
System.out.println(acct3);
}
}
this reference is used to differentiate between instance variable and superclass variable with same name.
or local variable of method and instance variable with same name.
Here in this code there is no superclass or method local variable.
public class ABC{
int amt; //this.amt means this "amt" variable
public void setAmt(int amt){
this.amt=amt;
}
}
This way "this" keyword is used.
here in this code there is no need of "this" keyword.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.