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

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

University

8 Qs

quiz-placeholder

Similar activities

Java Class vocabulary

Java Class vocabulary

9th Grade - University

12 Qs

Final Exam Review

Final Exam Review

University

13 Qs

Python Quiz Infytq

Python Quiz Infytq

University

10 Qs

Flutter Quiz

Flutter Quiz

University

10 Qs

Q8 - Info Mgt

Q8 - Info Mgt

University

10 Qs

CS201: Chapter 5

CS201: Chapter 5

University

13 Qs

Delegates C#

Delegates C#

University

7 Qs

Python_OOP_Intro_Quiz

Python_OOP_Intro_Quiz

University

13 Qs

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

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

Assessment

Quiz

Computers

University

Hard

Created by

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.