
lab - (7 of 17) Properties Versus Methods from Explorations
Authored by Harold Peaden
Computers
University

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
8 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 12 pts
What is the primary purpose of a property in a Swift instance?
To perform repeated actions on the instance.
To provide or retrieve values specific to the instance.
To manage side effects related to the instance.
To execute complex logic using arguments.
Answer explanation
Correct Answer:
Explanation: A property provides a way to get or set a value that belongs to an instance. It does not perform additional work or require arguments.
2.
MULTIPLE CHOICE QUESTION
30 sec • 12 pts
What is the relationship between methods and properties in Swift?
Methods refer to values, while properties provide behavior.
Methods and properties are interchangeable in usage.
Properties access values, while methods provide behavior specific to the instance.
Properties handle side effects, while methods manage data retrieval.
Answer explanation
Correct Answer:
Explanation: Properties are used for accessing or setting values, while methods are for executing behavior or functionality tied to the instance.
3.
MULTIPLE CHOICE QUESTION
30 sec • 13 pts
Why does the removeAll() method qualify as a method instead of a property?
It requires arguments to function.
It involves side effects by modifying the instance.
It retrieves a value without performing additional work.
It is designed to calculate and return a value.
Answer explanation
Correct Answer:
Explanation: The removeAll() method modifies the instance (by emptying the string), which is considered a side effect, distinguishing it as a method.
4.
MULTIPLE CHOICE QUESTION
30 sec • 13 pts
Which of the following statements about methods and properties is true?
Methods can take arguments, while properties cannot.
Properties are designed to handle repeated actions.
Methods and properties cannot be defined in custom types.
Properties always involve additional computations.
Answer explanation
Correct Answer:
Explanation: Methods can accept arguments to perform specific tasks, whereas properties do not take arguments and are used solely for accessing or setting values.
5.
MULTIPLE CHOICE QUESTION
30 sec • 14 pts
Which scenario requires the use of a method rather than a property?
Retrieving the current value of an instance variable.
Performing an action that modifies the instance.
Storing data to be used later in the app.
Accessing a constant value shared across instances.
Answer explanation
Correct Answer:
Explanation: Methods are necessary for actions that modify the instance or require additional information, such as the removeAll() method that clears a string.
6.
MULTIPLE CHOICE QUESTION
30 sec • 12 pts
Which of the following best describes how apps typically use methods and properties?
Apps rely mostly on global variables and functions instead of methods and properties.
Most of the code in an app involves instance methods and properties on types.
Properties are rarely used, and methods perform all instance-related tasks.
Both methods and properties are defined only on predefined types, not custom types.
Answer explanation
Correct Answer:
Explanation: In app development, much of the code consists of instance methods and properties on types, often custom types, all working together to form the app’s functionality.
7.
MULTIPLE CHOICE QUESTION
30 sec • 12 pts
Why must hasPrefix() be a method instead of a property?
It performs a calculation that retrieves an instance’s value.
It modifies the instance by clearing its contents.
It requires a prefix as an argument to perform its function.
It accesses a constant value within the instance.
Answer explanation
Correct Answer:
Explanation: The hasPrefix() method needs a prefix argument to perform its check, making it a method rather than a property, as properties cannot take arguments.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?