Cards (110)

  • A method is a named block of code that performs a specific task
  • The access modifier in a method header determines the visibility of the method
  • The method name is a unique identifier for the method.

    True
  • Methods promote reusability by allowing the same functionality to be used without duplication
  • Abstraction in methods allows you to focus on what a method does rather than its implementation
  • A return type of 'void' indicates that the method does not return any data
  • The 'calculateArea' method calculates the area of a rectangle using its length and width.

    True
  • The parameter list in a method header includes input values enclosed in parentheses
  • A method with a return type of `void` does not return any data.

    True
  • What are parameters in a method definition?
    Input values accepted
  • Steps to calculate the area of a rectangle using a method:
    1️⃣ Define the method header with parameters (length, width)
    2️⃣ Specify the return type (int)
    3️⃣ Write the method body to multiply length and width
    4️⃣ Return the calculated area
  • A method definition includes both a method header and a method body.
    True
  • What is the modularity principle in method design?
    Breaks code into smaller units
  • The access modifier of a method determines its visibility.
    True
  • The parameter list in a method must be enclosed in parentheses.
    True
  • Parameters are defined in the method header and enclosed in parentheses.
    True
  • What is the return type of the method `calculateArea(int length, int width)`?
    int
  • What keyword indicates a void method in Java?
    void
  • What does method overloading allow in Java?
    Multiple methods with same name
  • The `calculateArea` method returns the area
  • Method overloading allows methods with the same name but different parameter lists within the same class.

    True
  • What is the purpose of the two `add` methods in the `Calculator` class?
    Add integers
  • Match the scope type with its description:
    Local Scope ↔️ Variables accessible within a method
    Instance Scope ↔️ Variables accessible throughout a class
  • Instance variables have instance scope, while local variables have local scope.

    True
  • Match the method header component with its description:
    Access Modifier ↔️ Determines method visibility
    Return Type ↔️ Indicates data type returned
    Method Name ↔️ Unique identifier for the method
    Parameter List ↔️ Input values the method accepts
  • Arrange the purposes of methods in object-oriented programming:
    1️⃣ Encapsulation
    2️⃣ Reusability
    3️⃣ Modularity
    4️⃣ Abstraction
  • Match the method syntax component with its example:
    Access Modifier ↔️ `public`
    Return Type ↔️ `int`, `String`, `void`
    Method Name ↔️ `calculateArea`, `getName`
    Parameter List ↔️ `(int length, int width)`
  • What does the access modifier in a method header determine?
    Method visibility
  • The input values a method accepts are called the parameter list.list
  • What specifies the type of data a method returns?
    Return type
  • What is the key difference between void and non-void methods in Java?
    Return a value
  • Give an example of a non-void method.
    calculateArea
  • Match the advantage of using methods with its description:
    Encapsulation ↔️ Groups related functionality
    Readability ↔️ Breaks down complex tasks
    Maintainability ↔️ Simplifies updates and debugging
    Reusability ↔️ Allows methods to be used across the class
  • Method overloading improves code reusability by allowing the same method name for similar tasks.
    True
  • Method overloading requires that methods with the same name have different parameter lists
  • Variables declared at the class level have instance scope.
  • A method should have only one purpose according to the Single Responsibility Principle.

    True
  • What should methods use to receive required input data?
    Parameters
  • Components of a method definition
    1️⃣ Method header
    2️⃣ Method body
  • The method body contains the code that executes the task