Modularisation Flashcards

1
Q

What is the purpose of methods?

A

To divide large complicated programs into smaller manageable pieces.

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

What are the two general categories of methods?

A
  • Program Control
  • Specific Task
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the return type in a method declaration?

A

The type of value that the method returns.

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

What is a formal parameter?

A

A variable declared in the method header that accepts input when the method is called.

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

What is the difference between a void method and a value-returning method?

A

A void method does not return a value, while a value-returning method does.

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

Fill in the blank: The process of transferring control to a called method is known as _______.

A

method calling

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

What is method overloading?

A

Defining multiple methods with the same name but different parameters.

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

What does it mean to pass parameters by value?

A

A copy of the value will be passed to a method

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

True or False: In Java, arrays are considered objects.

A

True

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

What are the eight primitive data types in Java?

A
  • byte
  • short
  • int
  • long
  • float
  • double
  • char
  • boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the scope of a variable?

A

The part of the program in which it may be referenced.

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

What is the duration of an identifier?

A

The time during which it exists in memory.

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

How do actual parameters differ from formal parameters?

A

Actual parameters are supplied when the method is called, while formal parameters are declared in the method header.

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

What is the significance of the main method?

A

It is where the program starts executing code.

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

What is the primary role of parameters in methods?

A

To communicate data between the calling program and the method being called.

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

True or False: A method can exist without being called.

17
Q

Fill in the blank: The _______ keyword allows us to create methods that do not return a value.

18
Q

What is the difference between method declarations and method calls?

A

Method declarations define the method’s structure, while method calls execute the method.

19
Q

What is an array in Java?

A

An array is an object and its name is an object reference variable. The array must be instantiated using ‘new’.

20
Q

True or False: In Java, an array can be passed as a parameter to a method.

21
Q

What happens to the original array when an element is changed within a method?

A

The original array is changed.

22
Q

List three goals of refactoring code.

A
  • Improve internal structure
  • Simplify complex logic
  • Reduce code duplication
23
Q

What is NOT a purpose of refactoring?

A

Adding new features.

24
Q

Describe the Extracting Method technique in refactoring.

A

Breaking down a large function into smaller, more manageable functions.

25
What is the Inlining Method technique?
Replacing a function call with the function's body.
26
When is it appropriate to use inlining?
For very simple, short methods.
27
When should you consider refactoring?
When you understand the code.
28
What are 'code smells'?
Indicators that code could be improved
29
Fill in the blank: Refactoring should ideally be an _______ process.
ongoing
30
What does a method header contain?
Modifier Return type Name Formal parameters