Lec 6: Methods Flashcards

1
Q

Define a method

A

A collection of statements that are grouped together to perform an operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define a method’s signature

A

the combination of the method name and the parameter list
ex: max(a,b)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define formal parameters

A

vars defined in the method header are known as formal parameters
ex: max(a,b)…a and b are formal parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define actual parameters

A

same as argument for a method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between instance and static methods

A

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();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or false: The switch check var can be a double

A

False; switch var cannot be a float-point number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define local variables

A

A variable defined inside a method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or false: A local variable must be declared before it can be used

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or false: You can declare a local variable with the same name multiple times in a the same nested blocks

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define “stepwise refinement”

A

The process of improving code piece by piece and to decompose bigger problems into smaller ones

How well did you know this?
1
Not at all
2
3
4
5
Perfectly