• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 2 pages
Exam (elaborations)

Assignment 2_ Theory solutions.

Document preview thumbnail
Preview 1 out of 2 pages

Assignment 2_ Theory solutions.

Content preview

Assignment 2: Theory solutions
What is the purpose of the keywords public and private in the class declaration? - correct
answer-The public keyword is used to declare a member variable or function that may be
directly accessed from outside the class.
The private keyword is used to declare a member variable or function that cannot be directly
accessed from outside the class. These members can only be accessed/modified with the
use of an accessor/mutator function.

What is the difference between a class and an object? - correct answer-A class is a user
defined type that defines a collection of properties and methods which can be accessed by
creating an instance of that class.
An object is an instance of a class. It is usually a real-world entity.

What does it mean to 'instantiate' an object? - correct answer-Instantiating an object is when
we create an instance of an object. The object is given a name and created in memory.

What is the purpose of a constructor? - correct answer-A constructor is used to initialize an
object when it is created.

What is the difference between the default constructor and the overloaded constructor? -
correct answer-Both have the same name that matches the class name,
A default constructor is one that takes no parameters and is automatically generated if the
user doesn't define one. It is used to assign default values to the member variables.
An overloaded constructor takes one or more parameters that assign custom values to the
member variables.

What is the purpose of a destructor? - correct answer-A destructor is used to free up
resources used by an object, it deallocates the memory and performs other cleanup actions.

What is the purpose of an accessor? - correct answer-An accessor is used to access/read
private class data from outside the class.

What is the purpose of a mutator? - correct answer-A mutator is used to modify/set/change
private class data from outside the class.

What is the purpose of the scope resolution operator? - correct answer-A scope resolution
operator can be used to:
• Access a global variable when there is a local variable with the same name
• Define a class function from outside the class
• Access a class's static variables

What is the difference between the scope resolution operator and the dot operator? - correct
answer-A scope resolution operator is used with a class name. It is two consecutive colons.
It indicates the class name to which an object belongs

Document information

Uploaded on
June 30, 2024
Number of pages
2
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers
$8.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
scholartutor
4.8
(923)
Sold
2789
Followers
3
Items
10777
Last sold
3 weeks ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions