lab - (7 of 17) Properties Versus Methods from Explorations

Quiz
•
Computers
•
University
•
Hard
Harold Peaden
FREE Resource
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.
8.
MULTIPLE CHOICE QUESTION
30 sec • 12 pts
What is a key difference between a property and a method?
A property can execute complex actions, while a method retrieves values.
A property provides or sets values, while a method performs actions, often with arguments.
Properties and methods both execute side effects equally.
Properties can be defined on types, but methods cannot.
Answer explanation
Correct Answer:
Explanation: Properties are for accessing or setting values, whereas methods perform actions, potentially involving arguments or side effects.
Similar Resources on Wayground
10 questions
Knowledge representations

Quiz
•
University
10 questions
Recap CSS

Quiz
•
University
10 questions
JAVA II

Quiz
•
University
10 questions
AITT LAB QUIZ 4

Quiz
•
University
8 questions
DBMS Day 4

Quiz
•
University
10 questions
Quizizz Tổng hợp kiến thức

Quiz
•
5th Grade - University
6 questions
DATA CLUSTERING ALGORITHM TEST 2

Quiz
•
University
10 questions
OOP - BASIC 16.12.24

Quiz
•
University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

Quiz
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
15 questions
Properties of Equality

Quiz
•
8th Grade - University
38 questions
WH - Unit 3 Exam Review*

Quiz
•
10th Grade - University
21 questions
Advise vs. Advice

Quiz
•
6th Grade - University
12 questions
Reading a ruler!

Quiz
•
9th Grade - University