Method Signatures
Help Questions
AP Computer Science A › Method Signatures
In BankAccount, what is the return type of deposit(double amount), which increases the account balance?
int
void
double
boolean
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, what is the return type of getBalance(), which reports the current account balance?
double
int
void
String
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.
In BankAccount, which parameter list would correctly overload withdraw(int dollars) without changing the method name?
withdraw()
withdrawal(int dollars)
withdraw(double amount)
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, which parameter list would correctly overload getBalance() while keeping the same method name?
getBalance(void)
getBalance(double fee)
getbalance(int fee)
getBalance()
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, in what scenario would you use deposit(int dollars) instead of deposit(double amount)?
When you need the account number returned.
When depositing a whole-dollar cash amount.
When you want to overload by return type.
When you must change the method’s visibility.
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, how does withdraw demonstrate overloading with withdraw(int dollars) and withdraw(double amount)?
They share a name but change parameter types.
They overload because one is public and one is private.
They overload by changing only the return type.
They overload by using different method names.
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, how does deposit demonstrate overloading with deposit(int dollars) and deposit(double amount)?
They overload by changing only the return type.
They overload because one method is static.
They overload by placing methods in different classes.
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.