zuai-logo
  • Home

  • Mock Exam

  • Cliffs

  • Talk to ZuAI

  • Request a Feature

zuai-logo
  1. Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion Bank
Revise later
SpaceTo flip
If confident

All Flashcards

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.
What are the steps to call a method with parameters?
1. Write the method name. 2. Include parentheses. 3. Pass arguments inside the parentheses that match the parameter types and order.
What are the steps to define a method with parameters?
1. Declare the method signature (access modifier, return type, method name). 2. Add parameters inside the parentheses (type and name). 3. Write the method body with code that uses the parameters.
What are the steps to overload a method?
1. Create multiple methods with the same name. 2. Ensure each method has a unique parameter list (different types, number, or order of parameters). 3. Implement each method's specific functionality.
What are the steps to trace the execution of a method call?
1. Identify the method call. 2. Substitute the argument values for the corresponding parameters. 3. Execute the code within the method. 4. Note any output or side effects.
What are the steps to handle a division by zero error in a method?
1. Check if the divisor is zero. 2. If the divisor is zero, return a predefined value (e.g., 0) or print an error message. 3. If the divisor is not zero, perform the division.
What are the steps to pass arguments to a method?
1. Identify the method's parameters. 2. Ensure the arguments match the parameters in type and order. 3. Place the arguments inside the parentheses when calling the method.
What are the steps to ensure a method handles invalid input?
1. Identify potential invalid inputs. 2. Add conditional statements to check for these inputs. 3. Provide appropriate error handling (e.g., return an error value or throw an exception).
What are the steps to determine which overloaded method is called?
1. Check the number of arguments. 2. Check the data types of the arguments. 3. The compiler selects the method whose parameters match the arguments in number and type.
What are the steps to debug a method with incorrect output?
1. Review the method's code. 2. Check parameter values. 3. Use print statements or a debugger to trace the execution and identify the source of the error.
What are the steps to test a method with different inputs?
1. Identify a range of input values. 2. Call the method with each input value. 3. Verify that the output matches the expected result for each input.