250+ TOP MCQs on Creating a Class and Answers

Visual Basic Multiple Choice Questions on “Creating a Class”.

1. Class is defined using ______________
a) Class statement
b) Object statement
c) Access specifier statement
d) Instance statement

Answer: a
Clarification: You define a class using the Class statement, which you enter in a class file. The steps for adding a class file to an open project are:
• Click Project on the menu bar and then click Add Class. The Add New Item dialog box opens with Class selected in the middle column of the dialog box.
• Type the name of the class followed by a period and the letters vb in the Name box, and then click the Add button.
The syntax of the class statement is as follows:

Public Class className
   attributes section
   behaviors section
End Class

2. The convention is to use ________________ case for classname.
a) Upper
b) Lower
c) Pascal
d) Mixed

Answer: c
Clarification: Although it is not a requirement, the convention is to use Pascal case for the class name. The names of Visual Basic classes (for example, Integer and TextBox) also follow this naming convention.

3. Objects are represented by _____________ variables and ______________ properties.
a) Private, Public
b) Public, Private
c) Protected, Public
d) Protected, Private

Answer: a
Clarification: Within the Class statement, you define the attributes and behaviors of the objects the class will create. In most cases, the attributes are represented by Private variables and Public properties. The behaviors are represented by methods, which can be Sub or Function procedures.

4. The behavior are represented by ______________
a) Methods
b) Attributes
c) Values
d) Numbers

Answer: a
Clarification: Within the Class statement, you define the attributes and behaviors of the objects the class will create. In most cases, the attributes are represented by Private variables and Public properties. The behaviors are represented by methods, which can be Sub or Function procedures.

5. After defining a class you can instantiate one or more ______________
a) Objects
b) Classes
c) Attributes
d) Methods

Answer: a
Clarification: After you define a class, it then can be used to instantiate one or more objects. The syntax is:

Syntax – Version 1

{Dim | Private} variableName As className
variableName = New className

Syntax – Version 2

{Dim | Private} variableName As New className

In both versions, className is the name of the class, and variableName is the name of a variable that will represent the object.

6. The computer creates the object when it processes the statement containing ____________ keyword.
a) Class
b) Object
c) New
d) Private

Answer: c
Clarification: After you define a class, it then can be used to instantiate one or more objects. The syntax is:

Syntax – Version 1

{Dim | Private} variableName As className
variableName = New className

Syntax – Version 2

{Dim | Private} variableName As New className

In both versions, className is the name of the class, and variableName is the name of a variable that will represent the object. The difference between both versions relates to when the object is actually created. The computer creates the object only when it processes the statement containing the New keyword.

7. The class statement groups _______________ item in one unit.
a) Related
b) Different
c) Same access specifier items
d) Different access specifier items

Answer: a
Clarification: In its simplest form, the Class statement can be used in place of the Structure statement. Like the Structure statement, the Class statement groups related items into one unit. However, the unit is called a class rather than a structure.

8. The name of the class file ends with _____________
a) .cla
b) .class
c) .cla
d) .vb

Answer: b
Clarification: The name of class file ends with .class extension. A class file contains the attributes and methods of the class; and if any instance of that class is created, it can use the attributes and methods of the class file. The class file contains the definition of the methods. The class is a blueprint of an object.

9. A constructor is a _____________
a) A function procedure
b) A sub procedure
c) Either a function procedure or a sub procedure
d) A property procedure

Answer: c
Clarification: A constructor is a special method of a class or structure in object-oriented programming that initializes an object of that type. A constructor is an instance method that usually has the same name as the class, and can be used to set the values of the members of an object, either to default or to user-defined values.

10. Which of the following statements is false?
a) A class can have only one constructor
b) A class can have multiple constructors
c) An object created from a class is referred to as instance of the class
d) An instance of a class is considered an object

Answer: a
Clarification: A class can have multiple constructors. A constructor can be empty, can contain arguments; and the attributes of the class are defined, by the way the objects are created using the different constructors. For example, while creating an object, if we pass arguments, then the constructor with arguments are called and the attributes are initialized to some value, else if no arguments are passed while creating objects, then an empty constructor is called by default, and the attributes are initialized to zero.

Leave a Reply

Your email address will not be published. Required fields are marked *