Quiz 11 -methods
id:
1. A synonym of arguments is:
return type method header variables parameters
2. True or false: You can only call a method if it is defined in the class you are using: true false
3. True or false: A void return type means that the method will return a blank String. true false
public void findChar (String theWord) { char the5Letter=theWord.charAt(4); return the5Letter; }
compile time error - you cant have a 5 in a variable
compile time error - return type are inconsistent
compile time error - we cant have a String as a parameter
it returns the 5th letter of the word
5. True or false: Once a method is finished, ALL local variables in that method are destroyed.
true false
6. In the class called PacMan, the proper constructor header could be:
I. public PacMan ()
II. public void PacMan()
III. public PacMan (String name)
I only II only III only I and III only All could work
7. The process of using the same name for a method but different signature is called:
overloading constuctors overclocking decompisition none of the above
8. Looking at the code:
public void doSomething(int x) { System.out.println("a"); } public void doSomething(double x) { System.out.println("b"); }
What will happen if doSomething (5.0) is called?
a is printed out b is printed out compile time error (you cant have 2 methods named the same run time error - it will compile but on running it will stop none of the above