Deck 11: Classes and Objects
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/60
Play
Full screen (f)
Deck 11: Classes and Objects
1
____ are the actions to which an object can respond.
A) Attributes
B) Events
C) Behaviors
D) Methods
A) Attributes
B) Events
C) Behaviors
D) Methods
B
2
You create a Public property using a ____.
A) Sub procedure
B) Function procedure
C) Property procedure
D) Set block
A) Sub procedure
B) Function procedure
C) Property procedure
D) Set block
C
3
You can overload any of the methods contained in a class.
True
4
Private variables represent properties that will be seen by anyone using an object created from the class.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
5
A ____ encapsulates the attributes and behaviors of the object it creates.
A) constructor
B) property
C) class
D) structure
A) constructor
B) property
C) class
D) structure
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
6
When naming the Private variables in a class, many programmers use the ____ as the first character and then use camel case for the remainder of the name.
A) dash
B) admiration sign
C) asterisk
D) underscore
A) dash
B) admiration sign
C) asterisk
D) underscore
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following instantiates a Product object and assigns it to the bookcase variable?
A) Dim bookcase As Product
B) Dim bookcase As New Product
C) Dim Product As bookcase
D) Dim bookcase As String
A) Dim bookcase As Product
B) Dim bookcase As New Product
C) Dim Product As bookcase
D) Dim bookcase As String
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
8
A Public property procedure creates a property that is visible to any application that contains an instance of the class.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
9
Only an instance of a class-not the class itself-is an object.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
10
Constructors never return a value, so they are always Function procedures.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
11
A class is anything that can be seen, touched, or used; in other words, a class is nearly any thing .
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
12
In its simplest form, the Class statement can be used in place of the Structure statement.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
13
The purpose of a(n) ____ in OOP is to encapsulate the properties that describe an object, the methods that allow the object to perform tasks, and the events that allow the object to respond to actions.
A) event
B) class
C) method
D) attribute
A) event
B) class
C) method
D) attribute
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
14
When a variable in a class is declared using the Public keyword, it can be used only within the class.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
15
In the following instruction, Room is a(n) ____. Dim bedroom As New Room
A) object
B) variable
C) class
D) property
A) object
B) variable
C) class
D) property
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
16
____ are the operations (actions) that the object is capable of performing.
A) Events
B) Attributes
C) Behaviors
D) Methods
A) Events
B) Attributes
C) Behaviors
D) Methods
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
17
A one-dimensional array's Length property is an example of a ReadOnly property.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
18
Every object has ____, which are the characteristics that describe the object.
A) events
B) methods
C) attributes
D) behaviors
A) events
B) methods
C) attributes
D) behaviors
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
19
The Class statement ends with the keyword(s) ____.
A) Class
B) Exit Class
C) End Class
D) Next Class
A) Class
B) Exit Class
C) End Class
D) Next Class
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
20
A class can have multiple default constructors.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
21
A(n) ____ is a class method whose sole purpose is to initialize the class's Private variables.
A) signature
B) constructor
C) Get block
D) event
A) signature
B) constructor
C) Get block
D) event
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
22
____ is useful when two or more methods require different parameters to perform essentially the same task.
A) Instantiation
B) Overloading
C) Encapsulation
D) Overriding
A) Instantiation
B) Overloading
C) Encapsulation
D) Overriding
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
23
Constructors that contain parameters are called ____.
A) attributes
B) default constructors
C) Set blocks
D) parameterized constructors
A) attributes
B) default constructors
C) Set blocks
D) parameterized constructors
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
24
Case-Based Critical Thinking Questions Case 1 - chaussure.com
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
Which of the following is a valid example of an object?
A) Place Order button in an application
B) credit card receipt
C) text box to enter the credit card number in an application
D) a and c
E) all of the above
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
Which of the following is a valid example of an object?
A) Place Order button in an application
B) credit card receipt
C) text box to enter the credit card number in an application
D) a and c
E) all of the above
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
25
The code in the ____ allows an application to assign a value to the Private variable associated with the property.
A) Get block
B) default constructor
C) Set block
D) Property procedure
A) Get block
B) default constructor
C) Set block
D) Property procedure
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
26
You can create one class from another class. In OOP, this is referred to as ____.
A) encapsulation
B) overloading
C) overriding
D) inheritance
A) encapsulation
B) overloading
C) overriding
D) inheritance
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
27
A(n) ____ property gets its value from the class itself rather than from the application.
A) WriteOnly
B) ReadOnly
C) Set block
D) Get block
A) WriteOnly
B) ReadOnly
C) Set block
D) Get block
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
28
When two or more methods have the same name but different parameters, the methods are referred to as ____.
A) default methods
B) parameterized methods
C) overloaded methods
D) Property procedures
A) default methods
B) parameterized methods
C) overloaded methods
D) Property procedures
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
29
You indicate that a class is a derived class by including the ____ clause in the derived class's Class statement.
A) Inherits
B) Base
C) Overrides
D) Overloads
A) Inherits
B) Base
C) Overrides
D) Overloads
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
30
Case-Based Critical Thinking Questions Case 1 - chaussure.com
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
An application needs to calculate the sales tax for an order. Which of the following is a valid example of a variable in a class that can be validated in the Set block of a Property procedure?
A) Private TaxRate As Double
B) Private _dblTaxRate As Double
C) Public TaxRate As Double
D) Public _dblTaxRate As Double
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
An application needs to calculate the sales tax for an order. Which of the following is a valid example of a variable in a class that can be validated in the Set block of a Property procedure?
A) Private TaxRate As Double
B) Private _dblTaxRate As Double
C) Public TaxRate As Double
D) Public _dblTaxRate As Double
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
31
The first word in a method name should be a(n) ____.
A) verb
B) noun
C) adjective
D) preposition
A) verb
B) noun
C) adjective
D) preposition
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
32
The Tree class is derived from a base class named Plant. Which of the following statements can be used by the Tree class to invoke the Plant class's default constructor?
A) MyPlant.New()
B) MyBase.New()
C) MyTree.New()
D) MyTree.Base
A) MyPlant.New()
B) MyBase.New()
C) MyTree.New()
D) MyTree.Base
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
33
A constructor that has no parameters is called the ____.
A) Property procedure
B) default constructor
C) parameterized constructor
D) Set block
A) Property procedure
B) default constructor
C) parameterized constructor
D) Set block
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
34
If you create an auto-implemented property named State, Visual Basic will create a hidden Private variable named ____.
A) State
B) _State
C) STATE
D) state_
A) State
B) _State
C) STATE
D) state_
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
35
In a Property procedure, the dataType must match the data type of ____ associated with the Property procedure.
A) all constructors
B) all variables
C) the Public variable
D) the Private variable
A) all constructors
B) all variables
C) the Public variable
D) the Private variable
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following clauses allows a derived class named Truck to have the same attributes and behaviors as its base class, which is named Automobile?
A) Inherit Truck
B) Inherits Truck
C) Inherit Automobile
D) Inherits Automobile
A) Inherit Truck
B) Inherits Truck
C) Inherit Automobile
D) Inherits Automobile
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
37
The Inherits clause is the keyword ____ followed by the name of the class whose attributes and behaviors you want the derived class to inherit.
A) It Inherits
B) InheritsFrom
C) Inherits
D) Inherits_From
A) It Inherits
B) InheritsFrom
C) Inherits
D) Inherits_From
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
38
In a Property procedure, the code contained in the ____ block allows an application to retrieve the contents of the Private variable associated with the property.
A) Set
B) Assign
C) New
D) Get
A) Set
B) Assign
C) New
D) Get
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
39
A Property procedure begins with the keywords ____.
A) Public [ReadOnly | WriteOnly] Property
B) Private [ReadOnly | WriteOnly] Property
C) Start [ReadOnly | WriteOnly] Property
D) Dim [ReadOnly | WriteOnly] Property
A) Public [ReadOnly | WriteOnly] Property
B) Private [ReadOnly | WriteOnly] Property
C) Start [ReadOnly | WriteOnly] Property
D) Dim [ReadOnly | WriteOnly] Property
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
40
A method name combined with its optional parameterList is called the method's ____.
A) signature
B) event
C) attribute
D) behavior
A) signature
B) event
C) attribute
D) behavior
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
41
Explain the difference between Public and Private variables for a class.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
42
Case-Based Critical Thinking Questions Case 1 - chaussure.com
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
Rather than reuse the Shoe class, you have decided to derive the Boot class from the Shoe class. Which of the following creates the derived Boot class?
A) Private Class Shoe Inherits Boot
B) Private Class Boot Inherits Shoe
C) Public Class Shoe Inherits Boot
D) Public Class Boot Inherits Shoe
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
Rather than reuse the Shoe class, you have decided to derive the Boot class from the Shoe class. Which of the following creates the derived Boot class?
A) Private Class Shoe Inherits Boot
B) Private Class Boot Inherits Shoe
C) Public Class Shoe Inherits Boot
D) Public Class Boot Inherits Shoe
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
43
Problems - Correcting Logic and Code Errors
The following sample of code contains errors. Rewrite the incorrect statements to correct all errors.
Public Class Employee
Private _strEmpId As String
Public _decSalary As Decimal
Public Property EmpId As String
Set(ByVal value As String)
_strEmpId = value
End Set
End Property
Public Property Salary As Decimal
Get
Return _decSalary
End Get
Set(ByVal value As Decimal)
Salary = value
End Set
End Property
Public Function New()
_strEmpId = String.Empty
_decSalary = 0
End Sub
End Class
The following sample of code contains errors. Rewrite the incorrect statements to correct all errors.
Public Class Employee
Private _strEmpId As String
Public _decSalary As Decimal
Public Property EmpId As String
Set(ByVal value As String)
_strEmpId = value
End Set
End Property
Public Property Salary As Decimal
Get
Return _decSalary
End Get
Set(ByVal value As Decimal)
Salary = value
End Set
End Property
Public Function New()
_strEmpId = String.Empty
_decSalary = 0
End Sub
End Class
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
44
Define the term "inheritance" in object-oriented programming and describe its use.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
45
Write a Class statement that defines a class named Employee. (The class contains four public variables named EmpID , LastName , FirstName , and PayRate . The EmpID , LastName , and FirstName variables are String variables. The PayRate variable is a Decimal variable.) Then write a statement that creates an Employee variable named partTime and also instantiates an Employee object, assigning it to the partTime variable.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
46
A base class named DeliveryFee contains a function named CalcFee that calculates an order's delivery fee using the following formula: total * .05. Write the method's procedure header in the base class that will allow the derived class to override the function.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
47
An application has a Private variable named _ decGPA . Write the statements for the Property procedure named GPA to validate the value received from the application before assigning it to the Private variable.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
48
The Lumber class definition contains two Private variables named _dblLength and _decPricePerFoot . The default constructor initializes the Private variables to 0 when the Lumber object is created. Write the statements to create a parameterized constructor, and then write the Dim statement using the parameterized constructor to instantiate and initialize the Lumber object where the number of feet of lumber is 31.5 and the price per foot is 1.85.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
49
Write a Class statement that defines a class named Furniture. The class contains two private variables named _strItemNum and _dblPrice . Name the corresponding properties ItemNumber and Price.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
50
A base class named DeliveryFee contains a function named CalcFee that calculates an order's delivery fee using the following formula: total * .05. The derived class named InstallationFee contains the CalcFee method. However, the fee formula is as follows: ( total * .05) + 250. Write the function for the derived class.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
51
Problems - Correcting Logic and Code Errors
The following sample of code contains errors. Rewrite the incorrect statements to correct all errors.
Public Class Truck
Private Property Miles As Decimal
Public Function New()
_Miles = 0
End Function
Public Sub New(ByVal decM As Decimal)
Miles = decM
End Sub
Public Overrider Function GetMPG() As Decimal
'returns the miles per gallon for a truck
Return _Miles / 30
End Function
End Class
'derived class
Public Class Car
Receives Truck
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal decM As Decimal)
MyBase.New(decM)
End Sub
Public Function GetMPG() As Decimal
Return _Miles / 18
End Function
End Class
The following sample of code contains errors. Rewrite the incorrect statements to correct all errors.
Public Class Truck
Private Property Miles As Decimal
Public Function New()
_Miles = 0
End Function
Public Sub New(ByVal decM As Decimal)
Miles = decM
End Sub
Public Overrider Function GetMPG() As Decimal
'returns the miles per gallon for a truck
Return _Miles / 30
End Function
End Class
'derived class
Public Class Car
Receives Truck
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal decM As Decimal)
MyBase.New(decM)
End Sub
Public Function GetMPG() As Decimal
Return _Miles / 18
End Function
End Class
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
52
Case-Based Critical Thinking Questions Case 1 - chaussure.com
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
The Shoe class is used to create an object that represents a standard shoe. The Shoe class needs to be used in an application for boots. You have copied the Shoe.vb file into the boot application. What do you need to do next to include the file in the boot application?
A) Click PROJECT on the menu bar and then click Add Existing Item.
B) Select the Shoe.vb file from the list of filenames.
C) Click PROJECT on the menu bar and then click Add Class.
D) Click the Add button to add the file.
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
The Shoe class is used to create an object that represents a standard shoe. The Shoe class needs to be used in an application for boots. You have copied the Shoe.vb file into the boot application. What do you need to do next to include the file in the boot application?
A) Click PROJECT on the menu bar and then click Add Existing Item.
B) Select the Shoe.vb file from the list of filenames.
C) Click PROJECT on the menu bar and then click Add Class.
D) Click the Add button to add the file.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
53
Write the appropriate block of code to complete a Public procedure based on the following statements:
Private _decTotalSales As Decimal
Public WriteOnly Property TotalSales As Decimal
End Property
Private _decTotalSales As Decimal
Public WriteOnly Property TotalSales As Decimal
End Property
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
54
Write the statements to create the default constructor for the Furniture class statement in the previous problem. Then write the Dim statement to use the default constructor to instantiate a Furniture object, assigning the object to a variable named sofa .
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
55
Every object has attributes and behaviors. Describe each of these, including the two types of behaviors an object can have.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
56
What is a constructor? Explain the difference between a default constructor and a parameterized constructor.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
57
What is an auto-implemented property and what does it automatically create?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
58
Case-Based Critical Thinking Questions Case 1 - chaussure.com
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
The Discount class is used by applications for assigning appropriate discounts to orders. A Public property within the class is made ReadOnly. Which of the following is true about this ReadOnly property?
A) The Set block of code will be entered in the class.
B) The applications using the Discount class will determine the appropriate discount.
C) The application will only be able to retrieve the discount.
D) The application will be able to change the discount.
Chaussure.com is an online shoe retailer. The applications for the web site are developed using classes and object-oriented programming techniques.
The Discount class is used by applications for assigning appropriate discounts to orders. A Public property within the class is made ReadOnly. Which of the following is true about this ReadOnly property?
A) The Set block of code will be entered in the class.
B) The applications using the Discount class will determine the appropriate discount.
C) The application will only be able to retrieve the discount.
D) The application will be able to change the discount.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
59
Write the code for an auto-implemented property named TaxableIncome. The property's data type is Decimal. Then list the two hidden items it creates.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
60
What are classes and objects? How are they used in object-oriented programming?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck