Lec 6: Methods Flashcards
Define a method
A collection of statements that are grouped together to perform an operation
Define a method’s signature
the combination of the method name and the parameter list
ex: max(a,b)
Define formal parameters
vars defined in the method header are known as formal parameters
ex: max(a,b)…a and b are formal parameters
Define actual parameters
same as argument for a method
What is the difference between instance and static methods
Instance methods can only be invoked from a specific instance or class, the syntax being referenceVar.methodName(args)
ex: message.length();
Static methods can be invoked without using an object
ex: Math.abs(x); and NOT x.abs();
True or false: The switch check var can be a double
False; switch var cannot be a float-point number
Define local variables
A variable defined inside a method
True or false: A local variable must be declared before it can be used
True
True or false: You can declare a local variable with the same name multiple times in a the same nested blocks
False
Define “stepwise refinement”
The process of improving code piece by piece and to decompose bigger problems into smaller ones