Chapter 14 – Advanced Object-Oriented Programming

chapter 14

Advanced Object-Oriented Programming

True-False Questions

1. Objects have properties.

Answer: True Level: Easy

Section: 14-1 Page: 390

2. Properties have methods.

Answer: False Level: Easy

Section: 14-1 Page: 390

3. All Controls are objects.

Answer: True Level: Easy

Section: 14-1 Page: 390

4. All Objects are controls.

Answer: False Level: Easy

Section: 14-1 Page: 390

5. Classes and objects are really the same thing.

Answer: False Level: Moderate

Section: 14-1 Page: 391

6. Actions and data that are grouped together are called objects.

Answer: True Level: Easy

Section: 14-1 Page: 391

7. The design of an object is called a class.

Answer: True Level: Moderate

Section: 14-1 Page: 391

8. A property is the action associated with an object.

Answer: False Level: Moderate

Section: 14-1 Page: 391

9. One class can create many objects.

Answer: True Level: Moderate

Section: 14-1 Page: 391

10. A class is an instance of an object.

Answer: False Level: Hard

Section: 14-1 Page: 391

11. Object oriented programming is considered just one way to deal with the inherent complexity of software development.

Answer: True Level: Moderate

Section: 14-2 Page: 391

12. The prefix for a class is T, which stands for text.

Answer: False Level: Moderate

Section: 14-2 Page: 392

13. One advantage of encapsulation is that it protects data in an object from external code.

Answer: True Level: Moderate

Section: 14-2 Page: 392

14. To ensure proper encapsulation internal variables are declared as public.

Answer: False Level: Moderate

Section: 14-2 Page: 392

15. Always use properties to encapsulate data.

Answer: True Level: Moderate

Section: 14-2 Page: 392

16. Only some properties and methods are inherited from a base class.

Answer: False Level: Moderate

Section: 14-2 Page: 392

17. Inheritance makes it easy to reuse existing code in new applications.

Answer: True Level: Easy

Section: 14-2 Page: 392

18. Making a change in a base class will always cause the derived class to change.

Answer: True Level: Easy

Section: 14-2 Page: 392

19. New properties can not be added to a derived class.

Answer: False Level: Moderate

Section: 14-2 Page: 392

20. Polymorphism means that one method can have many names.

Answer: False Level: Hard

Section: 14-2 Page: 393

21. The fact that multiplication can apply to a variety of data types is an example of polymorphism.

Answer: True Level: Moderate

Section: 14-2 Page: 393

22. The two parts of a class definition are properties and methods.

Answer: False Level: Moderate

Section: 14-3 Page: 393

23. A property is a privately defined variable in a class.

Answer: False Level: Moderate

Section: 14-3 Page: 393

24. A class method can be either a function procedure or a sub procedure.

Answer: True Level: Moderate

Section: 14-3 Page: 393

25. When a constructor is called, it means a new object is created.

Answer: True Level: Easy

Section: 14-3 Page: 393

26. It is best to define a field as a private variable.

Answer: True Level: Easy

Section: 14-3 Page: 394

27. A field should have a prefix of P, which stands for private.

Answer: False Level: Easy

Section: 14-3 Page: 394

28. The standard way to interact with a private field is to use a property.

Answer: True Level: Easy

Section: 14-3 Page: 395

29. The get procedure of a property is used to assign a value to field.

Answer: False Level: Moderate

Section: 14-3 Page: 395

30. The best way to make a property read only is to not put code in the Set procedure.

Answer: False Level: Moderate

Section: 14-3 Page: 395

31. A method in a class can only be defined as Public.

Answer: False Level: Moderate

Section: 14-3 Page: 396

32. A method in a class can read any field in that class.

Answer: True Level: Moderate

Section: 14-3 Page: 396

33. Having multiple constructors in a class is an example of polymorphism.

Answer: True Level: Hard

Section: 14-3 Page: 397

34. A constructor is a property that is used to create a new object.

Answer: False Level: Moderate

Section: 14-3 Page: 397

35. The code to call the constructor of a base class is MyBaseClass.New().

Answer: False Level: Moderate

Section: 14-3 Page: 397

36. Parameters are required in a call to a constructor.

Answer: False Level: Moderate

Section: 14-3 Page: 397

Multiple Choice Questions

37. Which control is an example of an object in VB.NET?

a.) Button

b.) Label

c.) Textbox

d.) Both a and b.

e.) All of the above.

Answer: e Level: Easy

Section: 14-1 Page: 390

38. Which of the following is part of an object?

a.) Methods

b.) Properties

c.) Instances

d.) Both a and b.

e.) All of the above.

Answer: d Level: Moderate

Section: 14-1 Page: 390

39. Which is true about objects?

a.) Objects are used to create classes.

b.) Objects are analogous to blueprints.

c.) Objects combine actions and data.

d.) Both a and b.

e.) All of the above.

Answer: c Level: Moderate

Section: 14-1 Page: 391

40. Properties are used to represent:

a.) actions.

b.) classes.

c.) data.

d.) events.

e.) instances.

Answer: c Level: Easy

Section: 14-1 Page: 391

41. Methods are used to represent:

a.) actions.

b.) classes.

c.) data.

d.) events.

e.) instances.

Answer: a Level: Easy

Section: 14-1 Page: 391

42. The term instantiation refers to the creation of:

a.) a class from a blueprint.

b.) an object from a class.

c.) a method from an object.

d.) a property from a method.

e.) a blueprint from a property.

Answer: b Level: Moderate

Section: 14-1 Page: 391

43. Anything in VB.NET that has a property or method is:

a.) a class.

b.) a control.

c.) an object.

d.) Both a and b.

e.) All of the above.

Answer: c Level: Moderate

Section: 14-1 Page: 391

44. Which feature is needed to make a programming language object oriented?

a.) Encapsulation

b.) Inheritance

c.) Polymorphism

d.) Both a and b.

e.) All of the above.

Answer: e Level: Easy

Section: 14-2 Page: 391

45. We should think of the practice of object-oriented programming as:

a.) a simple answer to the complex problem of creating software.

b.) an incremental improvement to the problem of creating software.

c.) the way to get rid of a werewolf.

d.) Both a and b.

e.) All of the above.

Answer: b Level: Moderate

Section: 14-2 Page: 391

46. Encapsulation makes it easier to:

a.) reuse and modify existing modules of code.

b.) write and read code by sharing method names.

c.) hide and protect data from external code.

d.) Both a and b.

e.) All of the above.

Answer: c Level: Moderate

Section: 14-2 Page: 392

47. Inheritance makes it easier to:

a.) reuse and modify existing modules of code.

b.) write and read code by sharing method names.

c.) hide and protect data from external code.

d.) Both a and b.

e.) All of the above.

Answer: a Level: Moderate

Section: 14-2 Page: 392

48. Polymorphism makes it easier to:

a.) reuse and modify existing modules of code.

b.) write and read code by sharing method names.

c.) hide and protect data from external code.

d.) Both a and b.

e.) All of the above.

Answer: b Level: Moderate

Section: 14-2 Page: 393

49. The standard prefix to signify a class is:

a.) B.

b.) C.

c.) L.

d.) S.

e.) T.

Answer: e Level: Moderate

Section: 14-2 Page: 392

50. When using encapsulation how should data be shared with external code?

a.) Events

b.) Methods

c.) Properties

d.) Private variables

e.) Public variables

Answer: c Level: Moderate

Section: 14-2 Page: 392

51. Which statement is true?

a.) A base class inherits some of the properties of a derived class.

b.) A base class inherits all of the properties of a derived class.

c.) A derived class inherits some of the properties of a base class.

d.) A derived class inherits all of the properties of a base class.

e.)  None of the above.

Answer: d Level: Moderate

Section: 14-2 Page: 392

52. When a base class is changed:

a.) there is no effect on the derived class.

b.) the derived class changes when the key word Overridden is used.

c.) only the methods of the derived class change.

d.) only the properties of the derived class change.

e.) the derived class automatically changes.

Answer: e Level: Easy

Section: 14-2 Page: 392

53. Polymorphism can apply to:

a.) math operators.

b.) method names.

c.) object names.

d.) Both a and b.

e.) All of the above.

Answer: d Level: Moderate

Section: 14-2 Page: 393

54. With polymorphism:

a.) one method can have multiple names.

b.) one object can have multiple names.

c.) many methods can share the same name.

d.) many objects can share the same name.

e.) None of the above statements are true.

Answer: c Level: Hard

Section: 14-2 Page: 393

55. Which element of a class is optional?

a.) Constructs

b.) Fields

c.) Methods

d.) Properties

e.) All of the above.

Answer: e Level: Moderate

Section: 14-3 Page: 394

56. What is the suggested order for the definition of class elements from first to last?

a.) Constructs, fields, methods, properties

b.) Properties, constructs, fields, methods

c.) Fields, properties, constructs, methods

d.) Constructs, properties, fields, methods

e.) Methods, constructs, properties, fields

Answer: c Level: Hard

Section: 14-3 Page: 394

57. The standard for designing a field is that it be defined as a:

a.) private method.

b.) public method.

c.) private variable.

d.) public variable.

e.) None of the above.

Answer: c Level: Moderate

Section: 14-3 Page: 393

58. What is the syntax for making a property read-only?

a.) Property Read propertyname As datatype

b.) Read Property propertyname As datatype

c.) ReadOnly Property propertyname As datatype

d.) Read-Only Property propertyname As datatype

e.) RO Property propertyname As datatype

Answer: c Level: Moderate

Section: 14-3 Page: 395

59. The Get procedure of a property acts like:

a.) an event.

b.) a function.

c.) a variable.

d.) Both a and b.

e.) All of the above.

Answer: b Level: Hard

Section: 14-3 Page: 395

60. A method in a class is:

a.) a sub procedure.

b.) a function.

c.) an event.

d.) Both a and b.

e.) All of the above.

Answer: d Level: Moderate

Section: 14-3 Page: 396

61. How many constructors can a class have?

a.) 0

b.) 1

c.) 2

d.) 3

e.) All of the above.

Answer: e Level: Easy

Section: 14-3 Page: 397

62. A constructor is a special type of:

a.) class.

b.) field.

c.) method.

d.) property.

e.) variable.

Answer: c Level: Easy

Section: 14-3 Page: 397

63. Which is true for constructors in a class?

a.) All constructors must have the same number of parameters.

b.) All constructors must be the same parameter data type.

c.) Some constructors can have the same list of parameters.

d.) Only two constructors in a class can have the same list of parameters.

e.) No two constructors in a class can have the same list of parameters.

Answer: e Level: Moderate

Section: 14-3 Page: 397

64. Which statement will call a constructor of a base class?

a.) Base.New( )

b.) BaseConstructor.New ( )

c.) CallBase.New( )

d.) Constructor.New ( )

e.) MyBase.New( )

Answer: e Level: Moderate

Section: 14-3 Page: 397

Fill in the Blank Questions

65. The controls on a form and the form itself are examples of ___objects___.

Level: Easy

Section: 14-1 Page: 390

66. The name and text of a textbox control are ___properties___ of the control.

Level: Moderate

Section: 14-1 Page: 390

67. The ___class___ is similar to a blueprint for the object.

Level: Moderate

Section: 14-1 Page: 391

68. Creating an object from a class is called ___instantiation___.

Level: Hard

Section: 14-1 Page: 391

69. Elements in VB.NET that have methods and properties are considered ___objects___.

Level: Moderate

Section: 14-1 Page: 391

70. The process of hiding the internal data and actions of an object is called ___encapsulation___.

Level: Easy

Section: 14-2 Page: 392

71. Objects should always use ___properties___ to interact with external code.

Level: Moderate

Section: 14-2 Page: 392

72. Internal methods and variables of an object should be declared ___private____.

Level: Moderate

Section: 14-2 Page: 392

73. Creating modified and specialized versions of an existing class is called ___inheritance___.

Level: Moderate

Section: 14-2 Page: 392

74. A(n) ___base___ class is used to create a derived class.

Level: Moderate

Section: 14-2 Page: 392

75. When a method in a derived class is modified, it is called a(n) ___overridden___ method.

Level: Moderate

Section: 14-2 Page: 392

76. Changes in a ___base___ class will propagate to all derived classes.

Level: Moderate

Section: 14-2 Page: 392

77. The capacity to have different methods all using the same name is called ___polymorphism___.

Level: Moderate

Section: 14-2 Page: 393

78. A single math operator can apply to different sets of data types is an example of ___polymorphism___.

Level: Moderate

Section: 14-2 Page: 393

79. A private variable is a class called a ___field___.

Level: Easy

Section: 14-3 Page: 393

80. Making a field in a class private helps to ensure ___data hiding___.

Level: Hard

Section: 14-3 Page: 394

81. The ___fields___ of a class should be defined first.

Level: Moderate

Section: 14-3 Page: 394

82. The ___Get___ procedure of a property is used to output data from an object.

Level: Hard

Section: 14-3 Page: 395

83. The ___Set___ procedure of a property is used for data input into an object.

Level: Hard

Section: 14-3 Page: 395

84. ___Properties___ are used to access private fields in an object.

Level: Moderate

Section: 14-3 Page: 395

85. You can prevent external code from changing the value of a property by using the ___ReadOnly___ keyword to define the property.

Level: Moderate

Section: 14-3 Page: 395

86. Procedures defined in a class are called ___methods___.