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

Next three (3) questions are based on the following java code import java.text D

ID: 3852015 • Letter: N

Question

Next three (3) questions are based on the following java code import java.text DecimalFormat, public class Account { private long acctNum; private String owner; private double balance; public Account(long num, String name, double initialDeposit) i acctNum-num; owner = name balance - initialDeposit; public Account(long num, String name) i acctNum-num; owner = name balance 0; public double getBalanceO f retum balance; public String toString) DecimalFormat df= new DecimalFormat("0.00"); return (acctNum+"|"name "|" +df.format(balance)); Question: In a driver class, which of the following can be used to instantiate a new Account a1? 0 A. new Account(a1); 0 B. new Account a1 = (999999999, "John Smith", 100); ° C. Account a1 = new Account(999999999, 100, "John Smith"); D. Account a1 new Account (999999999, "John Smith");

Explanation / Answer

Question (1)

Option D

In an Given "Account" class there are two methods naming account but they are differ in variable passing
method 1 as " public Account(long num,String name,double initialDeposit) " having three inputs.
method 2 as " public Account(long num,String name) " having two inputs.

To instantiate a new Account a1 we have two possibilities they are
1) Account a1 = new Account(999999999,"John Smith"); or
2) Account a1 = new Account(999999999,"John Smith",100);

So,from the given options option D is true option C is false because it differs in input variable passing as in place of string type it is passed with value "100" and in place of double data type it passes string "John Smith" which is unlike the second posibility.

Question (2)

Option C

Here, in this case the output statement is "System.out.println(a1)" gives the memory address of a1 object.If we want to print any values in an object it has to be called with object reference as "a1.______".

Question (3)

Option B

From the given options option B is correct. We have "getbalance()" function in class Account that returns "balance".So, using that function we get a1's balance and it has to be call with object reference as "a1.getBalance()" and it is the only option to select.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote