Method Signatures
Help Questions
AP Computer Science A › Method Signatures
In BankAccount, how does withdraw demonstrate overloading with withdraw(int dollars) and withdraw(double amount)?
They overload because one is public and one is private.
They overload by using different method names.
They overload by changing only the return type.
They share a name but change parameter types.
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. Overloading allows multiple methods with the same name but different parameter lists. In the provided BankAccount class, the withdraw method demonstrates overloading with withdraw(int dollars) and withdraw(double amount) by using different parameter types. Choice A is correct because these methods share the same name 'withdraw' but have different parameter types (int vs double). Choice B is incorrect because overloading cannot be achieved by changing only the return type - the parameter lists must differ. To help students: Emphasize that overloading is determined by method name and parameter list, not return type. Practice identifying overloaded methods by comparing their signatures.
In BankAccount, in what scenario would you use deposit(int dollars) instead of deposit(double amount)?
When depositing a whole-dollar cash amount.
When you need the account number returned.
When you must change the method’s visibility.
When you want to overload by return type.
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. Overloading allows multiple methods with the same name but different parameter lists. In the provided BankAccount class, deposit(int dollars) accepts whole dollar amounts while deposit(double amount) accepts amounts with cents. Choice A is correct because deposit(int dollars) would be used when depositing whole-dollar cash amounts without cents. Choice D is incorrect because overloading cannot be achieved by changing only the return type - the parameter lists must differ. To help students: Emphasize practical scenarios where different parameter types serve different purposes. Practice choosing the appropriate overloaded method based on the data being processed.
In BankAccount, which parameter list would correctly overload withdraw(int dollars) without changing the method name?
withdrawal(int dollars)
withdraw(double amount)
withdraw()
withdraw(int dollars)
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. Overloading allows multiple methods with the same name but different parameter lists. In the provided BankAccount class, to overload withdraw(int dollars), we need a method with the same name but different parameters. Choice B is correct because withdraw(double amount) has the same method name but a different parameter type (double instead of int). Choice D is incorrect because 'withdrawal' is a different method name, which creates a new method rather than overloading. To help students: Emphasize that overloading requires keeping the same method name while changing parameters. Practice creating overloaded methods with different parameter types.
In BankAccount, what is the return type of deposit(double amount), which increases the account balance?
double
void
boolean
int
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. In the provided BankAccount class, the method deposit(double amount) increases the account balance. Choice A is correct because deposit methods typically return void, as they perform an action (updating the balance) rather than calculating and returning a value. Choice C is incorrect because returning double would suggest the method calculates something to return, which is not the primary purpose of a deposit operation. To help students: Emphasize that void methods perform actions without returning values. Practice identifying when methods should return values versus when they should be void.
In BankAccount, how does deposit demonstrate overloading with deposit(int dollars) and deposit(double amount)?
They overload by placing methods in different classes.
They overload because one method is static.
They overload by changing only the return type.
They share a name but use different parameter types.
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. Overloading allows multiple methods with the same name but different parameter lists. In the provided BankAccount class, deposit demonstrates overloading with deposit(int dollars) and deposit(double amount) by using different parameter types. Choice B is correct because these methods share the same name 'deposit' but use different parameter types (int vs double). Choice A is incorrect because overloading cannot be achieved by changing only the return type - the parameter lists must differ. To help students: Emphasize that overloading is based on method name and parameter list combinations. Practice recognizing valid overloads by examining parameter differences.
In BankAccount, which parameter list would correctly overload getBalance() while keeping the same method name?
getBalance(void)
getbalance(int fee)
getBalance()
getBalance(double fee)
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. Overloading allows multiple methods with the same name but different parameter lists. In the provided BankAccount class, to overload getBalance(), we need to add parameters since the original has none. Choice A is correct because getBalance(double fee) adds a parameter, creating a valid overload. Choice C is incorrect because 'void' is not a valid parameter - it's a return type keyword that cannot be used as a parameter. To help students: Emphasize that overloading requires different parameter lists, not just adding keywords. Practice creating overloaded methods by adding meaningful parameters.
In BankAccount, in what scenario would you use withdraw(double amount) rather than withdraw(int dollars)?
When you need to change the method name.
When withdrawing an amount with cents included.
When you want a constructor to run.
When the return type must become int.
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. Overloading allows multiple methods with the same name but different parameter lists. In the provided BankAccount class, withdraw(double amount) accepts decimal values while withdraw(int dollars) accepts only whole numbers. Choice A is correct because withdraw(double amount) would be used when withdrawing an amount that includes cents (like $25.50). Choice D is incorrect because constructors have different purposes and naming conventions than regular methods. To help students: Emphasize choosing the appropriate overloaded method based on data precision needs. Practice scenarios where different parameter types serve different use cases.
In BankAccount, what is the return type of getBalance(), which reports the current account balance?
double
String
void
int
Explanation
This question tests understanding of method signatures and overloading in Java, as covered in AP Computer Science A. Method signatures in Java define the method name, return type, and parameters. In the provided BankAccount class, the method getBalance() is designed to report the current account balance. Choice B is correct because getBalance() returns double, which is appropriate for representing monetary values with decimal places. Choice C is incorrect because void would mean the method returns nothing, which wouldn't allow it to report the balance value. To help students: Emphasize the importance of choosing appropriate return types based on the method's purpose. Practice identifying return types by considering what data the method needs to provide.