Save
AP Computer Science A
Unit 5: Writing Classes
5.2 Methods
Save
Share
Learn
Content
Leaderboard
Share
Learn
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
See all 110 cards
See similar decks
5.2 Methods
AP Computer Science A > Unit 5: Writing Classes
57 cards
5.2 Methods
AP Computer Science A > Unit 5: Writing Classes
57 cards
5.2 Methods
AP Computer Science A > Unit 5: Writing Classes
57 cards
5.2 Methods
AP Computer Science A > Unit 5: Writing Classes
57 cards
Unit 5: Writing Classes
AP Computer Science A
284 cards
5.1 Defining Classes
AP Computer Science A > Unit 5: Writing Classes
88 cards
AP Computer Science Principles
1196 cards
AP Computer Science A
1898 cards
5.3 Constructors
AP Computer Science A > Unit 5: Writing Classes
86 cards
OCR A-Level Computer Science
2091 cards
OCR GCSE Computer Science
1937 cards
AQA A-Level Computer Science
5135 cards
Edexcel GCSE Computer Science
2949 cards
AQA GCSE Computer Science
2308 cards
1.6.2 Legislation Relevant to Computer Science
OCR GCSE Computer Science > 1.6 Ethical, Legal, Cultural and Environmental Impacts of Digital Technology
39 cards
2.3 Wrapper Classes
AP Computer Science A > Unit 2: Using Objects
50 cards
9.2 Overriding Methods
AP Computer Science A > Unit 9: Inheritance
55 cards
Topic 3: Computers
Edexcel GCSE Computer Science
454 cards
Unit 7: ArrayList
AP Computer Science A
87 cards
7.2 ArrayList Methods
AP Computer Science A > Unit 7: ArrayList
43 cards
Unit 9: Inheritance
AP Computer Science A
223 cards