Questions
- What is wrong with this method definition?
doSomething(){ Â Â Â // Do something here }No return type is declared. You do not have to return a value from a method, but its return type must be
voidin this case. This is how the method should look:void doSomething(){ Â Â Â // Do something here } - What is wrong with this method definition?
float getBalance(){ Â Â Â String customerName = "Linus Torvalds"; Â Â Â float balance = 429.66f; Â Â Â return userName; }The method returns a string (
userName) but the signature states that it must return afloattype. With a method name likegetBalance, this code is what was likely intended:float getBalance(){ Â Â Â String customerName = "Linus Torvalds"; Â Â Â float balance = 429.66f; Â Â Â return balance; } - When do we call the
onCreatemethod? (Trick question alert!)We don't. Android decides when to call the...