All Flashcards
What is a method parameter?
Input passed into a method, used to customize its behavior.
What is a method signature?
The method's name and the types and order of its parameters.
What does void mean in a method signature?
The method does not return any value.
What is method overloading?
Having multiple methods with the same name but different parameter lists.
What is the purpose of parameters?
To make methods more flexible and reusable by allowing them to operate on different data.
What are actual parameters?
The values passed to a method when it is called.
What are formal parameters?
The parameters declared in the method signature.
What is the scope of a parameter?
The region of the program where the parameter is accessible, typically within the method's body.
What is a default parameter?
A parameter that has a default value specified in the method signature, used if no value is provided when the method is called.
What is the return type of a method?
The data type of the value that the method returns after its execution. If a method does not return a value, its return type is void.
What are the differences between parameters and local variables?
Parameters: Passed into a method. | Local variables: Declared inside a method.
What are the differences between method overloading and method overriding?
Overloading: Same name, different parameters. | Overriding: Same name and parameters, different implementation (in inheritance).
What are the differences between pass-by-value and pass-by-reference?
Pass-by-value: A copy of the value is passed. | Pass-by-reference: The memory address of the variable is passed (Java uses pass-by-value).
What are the differences between arguments and parameters?
Arguments: The actual values passed to a method when it is called. | Parameters: Variables in the method definition that receive the arguments.
What are the differences between formal and actual parameters?
Formal Parameters: Declared in the method signature. | Actual Parameters: The values passed during the method call.
What are the differences between instance and static methods?
Instance Methods: Belong to an instance of a class, can access instance variables. | Static Methods: Belong to the class itself, can only access static variables.
What are the differences between primitive and reference parameters?
Primitive Parameters: Pass-by-value, changes inside the method do not affect the original variable. | Reference Parameters: Pass-by-value (of the reference), changes inside the method can affect the original object.
What are the differences between using multiple parameters and using a single object as a parameter?
Multiple Parameters: Simple data types passed individually. | Single Object Parameter: Complex data types grouped into a single object, easier to manage related data.
What are the differences between void methods and methods that return a value?
Void Methods: Do not return a value, perform actions. | Methods with Return Value: Return a value after execution, can be used in expressions.
What are the differences between using parameters and using global variables?
Parameters: Scope is limited to the method, promotes modularity. | Global Variables: Scope is the entire program, can lead to unintended side effects.
Why are parameters important for methods?
They allow methods to be flexible and perform different actions based on input.
How does the order of parameters matter?
The order must match the order defined in the method signature when calling the method.
What happens if you call a method with the wrong number of parameters?
A compile-time error occurs because the method signature doesn't match the call.
How does method overloading increase code reusability?
It allows you to use the same method name for different operations based on the input parameters.
What are the key benefits of using methods with parameters?
Increased code reusability, flexibility, and modularity.
What is the relationship between parameters and arguments?
Parameters are variables in the method definition, while arguments are the actual values passed to these parameters when the method is called.
What are the advantages of using parameters in methods?
Parameters allow methods to be more versatile, reducing code duplication and making programs easier to maintain.
How does parameter passing work in Java?
Java uses pass-by-value. This means that a copy of the variable's value is passed to the method. Changes to the parameter inside the method do not affect the original variable outside the method.
What is the purpose of using different data types for parameters?
Using different data types ensures that the method receives the correct type of data it expects, preventing errors and ensuring proper operation.
How does method overloading improve code readability?
Method overloading allows you to use the same method name for similar operations, making the code more intuitive and easier to understand.