SPRING '25 FINAL Flashcards
(70 cards)
What are method modifiers?
Modifiers define the visibility or accessibility of the method
Examples include public, private, and protected.
What is the return type of a method that does not return a value?
void
Indicates that the method does not return any value.
What is included in a method’s definition?
Return type, method name, parameter list in parentheses
The method definition outlines how the method operates.
What happens when a method is called in terms of memory?
A new memory space is created for the method
This allows for the method to execute without affecting the caller’s memory.
In the context of memory, what does ‘max gets a new value X’ imply?
The variable max receives a new value during method execution
This indicates the method’s ability to change local variables.
What is the purpose of the return statement in a method?
To return a value if there is a return type
If the method is void, no value will be returned.
What is meant by ‘PassByReference’?
Refers to passing a reference to the original data, not a copy
Modifications to the data affect the original data.
What is the difference between shallow copy and deep copy?
Shallow copy creates a new reference to the same object, deep copy creates a new object with its own data
Shallow copy shares the same elements, deep copy duplicates them.
What does the operation ‘newArray = originalArray’ signify?
newArray references the same array object as originalArray
This is an example of shallow copying.
Does modifying originalArray affect newArray?
Yes, if newArray is a shallow copy of originalArray
Changes to the original array will reflect in the new array.
Fill in the blank: A block of code that performs a specific task is called a _______.
method
Methods are fundamental building blocks in programming.
What does ‘workspace for main method’ refer to?
The memory space allocated for executing the main method
Each method has its own workspace to manage variables.
True or False: The originalArray has random numbers filled by default.
False
By default, an array is filled with default values (e.g., 0 for integers).
What is the significance of the ‘temp’ variable in swapping?
It temporarily holds a value to facilitate the swap
This is a common technique in variable swapping.
What do you call the method that executes code to find the maximum value?
findMax
This method is likely designed to compare two values and return the larger one.
What is the initial state of numA and numB in memory?
numA = 10, numB = 15
These are example values that would be used in operations.
What does ‘workspace for findMax method’ indicate?
Memory space allocated for the execution of the findMax method
Each method’s execution is isolated in its own workspace.
What is an array?
A container object that holds a fixed number of values of a single type
Each item in an array is called an element and is accessed by its numerical index.
What is the default value for elements in a primitive type array?
0
For reference types, the default value is null.
What is the syntax to declare an array of integers with a size of 5?
int[] scores = new int[5];
What is a 2D array?
An array that holds data points in a matrix format
It can be visualized as having rows and columns.
How do you access an element in a 2D array located at row 0, column 1?
data[0][1]
What is the declaration syntax for a 2D array with 5 rows and 6 columns?
int[][] data = new int[5][6];
What does data.length represent in a 2D array?
The size of the 1st dimension, which is the number of rows.