Chapter 19: How to work with inheritance MULTIPLE CHOICE 1

advertisement
Chapter 19: How to work with inheritance
MULTIPLE CHOICE
1. When used correctly, inheritance can
a.
b.
c.
d.
make an application run faster
make it easier to write the code for the application
simplify the overall design of an application
eliminate the need for casting
ANS: C
2. In the System.Windows.Forms namespace, the Control class
a.
b.
c.
d.
provides properties and methods that all controls in the namespace have in common
inherits the properties and methods from all of the control classes in the namespace
is the base class for the Button, TextBox, and Label classes, but not the Form class
is a child class of the Form class
ANS: A
3. The ToString, Equals, and GetHashCode methods are available to all objects because
a.
b.
c.
d.
they are defined in the System namespace
they are inherited by the System.Object class, which all other objects are based on
they are members of the System.Object class, which all objects inherit
they are defined with Public access
ANS: C
4. A Protected method defined within a base class is available to
a.
b.
c.
d.
only the base class
only classes derived from the base class
both the base class and classes derived from it
neither the base class nor classes derived from it
ANS: C
5. If the Student class inherits the Person class and overrides a method named GetBirthday, what feature
does the following code example illustrate?
Dim s As New Student("Albert Einstein")
Dim p As Person = s
p.GetBirthday()
a. Inheritance
b. Encapsulation
ANS: C
c. Polymorphism
d. Hiding
6. If the Student class inherits the Person class and overrides a method named GetBirthday, which method
does the third statement in the following code example call?
Dim s As New Student("Albert Einstein")
Dim p As Person = s
p.GetBirthday()
a.
b.
c.
d.
the GetBirthday method defined in the Person class
the GetBirthday method defined in the Student class
the GetBirthday method defined in the Object class
none of the above
ANS: B
7. The GetType method of an object returns
a.
b.
c.
d.
a Type enumeration that identifies the object’s type
a Type object that contains information about the object’s type
a string that contains the name of the object’s type
an integer value that identifies the type of the object
ANS: B
8. If the Student class inherits the Person class and Option Strict is on, which of the following statements is
true?
a. You must explicitly cast a Person object to a Student object whenever a Student object is
expected.
b. You must explicitly cast a Student object to a Person object whenever a Student object is
expected.
c. You must explicitly cast a Person object to a Student object whenever a Person object is
expected.
d. You must explicitly cast a Student object to a Person object whenever a Person object is
expected.
ANS: A
9. A class can
a.
b.
c.
d.
have only one derived class
be the base class for only one derived class
be only a base class or a derived class
be both a base class and a derived class
ANS: D
10. Which of the following method declarations overrides the method that is declared as follows?
Public Overridable Function CalculateMPG(ByVal speed as Double) As Double
a.
b.
c.
d.
Public
Public
Public
Public
New Function CalculateMPG(ByVal s As Integer) As Double
Overrides Function CalculateMPG(ByVal speed As Integer) As Double
New Function CalculateMPG(ByVal speed As Double) As Double
Overrides Function CalculateMPG(ByVal s As Double) As Double
ANS: D
Diagram 19-1
11. (Refer to diagram 19-1.) If the constructor for the WaterCraft class is called, the default constructors for
what other class or classes are also called?
a.
b.
c.
d.
Sailboat
Canoe
Sailboat and Canoe
Vehicle
ANS: D
12. (Refer to diagram 19-1.) If the MotorVehicle class contains a Protected method named GetEngineType,
what other class or classes can access this method?
a. Vehicle, Automobile, and Motorcycle
b. Vehicle and WaterCraft
c. Automobile and Motorcycle
d. Vehicle
ANS: C
13. If a method accepts an Object type, what types of objects can it accept?
a.
b.
c.
d.
None
All objects
Only objects created from classes in the System namespace
Only objects created from classes that explicitly inherit the Object class
ANS: B
14. Which of the following is not a reason to declare a class as sealed?
a.
b.
c.
d.
To prevent others from inheriting the class
To improve efficiency
To prevent others from changing how the methods work
To give a class more functionality
ANS: D
15. Which of the following can you not code in a derived class?
a. A method that overrides a method in the base class
b. A call to a constructor of the base class
c. A new method that’s not defined by the base class
d. A call to a private method of the base class
ANS: D
Chapter 20: How to work with interfaces and generics
MULTIPLE CHOICE
1. Which of the following statements about interfaces is not true?
a.
b.
c.
d.
An interface can only declare abstract members.
An interface can inherit other interfaces.
A class can only implement a single interface.
A class that implements an interface must provide an implementation for every member of
the interface.
ANS: C
2. Which of the following is a difference between interfaces and abstract classes?
a. None of the members of an interface can be implemented, but some of the members of an
abstract class can be.
b. An interface can declare shared members, but an abstract class can’t.
c. An interface can’t inherit multiple classes, but an abstract class can.
d. All of the above.
ANS: A
3. Given an interface named IWriteable, what type of object can be passed to the Save method that has the
following declaration?
Public Function Save(ByVal obj As IWriteable) As Boolean
a.
b.
c.
d.
any object
any object that implements the IWriteable interface
any object that implements the Save method
only objects created from the IWriteable class
ANS: B
Code example 20-1
Public Interface IPrintable
Sub Print()
End Interface
Public Class Printer
Public Shared Sub Print(ByVal p As IPrintable)
MessageBox.Show("Print")
p.Print()
End Sub
End Class
Public Class Order Implements IPrintable
Public Sub Print()
MessageBox.Show("Order")
End Sub
End Class
Public Class Transaction
End Class
Public Class Rental Inherits Transaction Implements IPrintable
Public Sub Print()
MessageBox.Show("Rental")
End Sub
End Class
4. (Refer to code example 20-1.) Which of the following statements will definitely not compile?
a. Dim p As IPrintable = New Order()
b. Dim rental As New Rental()
Dim p As IPrintable = rental
c. Dim p As New IPrintable()
d. Dim t As Transaction = New Rental()
ANS: C
5. (Refer to code example 20-1.) What happens when the code that follows is executed?
Dim order As New Order()
order.Print()
a. “Print” is displayed in a message box.
b. “Order” is displayed in a message box.
c. “Print” is displayed in a message box and then “Order” is displayed in a second message
box.
d. A runtime error occurs because the Print method can’t accept Rental objects.
ANS: B
6. (Refer to code example 20-1.) What happens when the code that follows is executed?
Dim r As New Rental()
Printer.Print(r)
a. “Print” is displayed in a message box.
b. “Rental” is displayed in a message box.
c. “Print” is displayed in a message box and then “Rental” is displayed in a second message
box.
d. A runtime error occurs because the Print method can’t accept Rental objects.
ANS: C
7. A method that accepts an interface as an argument can accept any object that
a.
b.
c.
d.
implements that interface
defines the same methods as the interface
implements the interface or defines the same methods as the interface
is created from that interface
ANS: A
8. A variable that stores an object that implements an interface can be declared as which of the following
data types?
a.
b.
c.
d.
e.
The class that defines the object
The interface that the object implements
Any subclass of the class that defines the object
All of the above
A and C only
ANS: D
9. The ICloneable interface defines a Clone method
a.
b.
c.
d.
that returns an object type
that accepts an object type as a parameter
that returns a specific type
that accepts a specific type as a parameter
ANS: A
10. The IComparable() interface defines a CompareTo method
a.
b.
c.
d.
that returns an object type
that accepts an object type as a parameter
that returns a specific type
that accepts a specific type as a parameter
ANS: D
11. If you implement the ICloneable interface for an Invoice that has a property that represents a Customer
object,
a.
b.
c.
d.
you must make sure that the clone refers to a different Customer object
you must make sure that the clone refers to the same Customer object
you must convert the Customer object to its composite value types
you can decide whether the clone refers to the same or a different Customer object
ANS: D
Chapter 22: How to work with files and data streams
MULTIPLE CHOICE
1. The primary difference between a text file and a binary file is that a binary file
a.
b.
c.
d.
stores data with different data types
stores data as fields
separates each record with a new line character
uses input and output streams
ANS: A
2. Which of the following is not the cause of a common I/O exception?
a.
b.
c.
d.
The directory can’t be found.
The file can’t be found.
The program tries to read beyond the end of a stream.
The path is too long.
ANS: D
3. To read a text file, you need to use a FileStream object and a
a. TextReader object
b. StreamReader object
c. RecordReader object
d. FieldReader object
ANS: B
4. When you use a method to read data from a text file, you normally read
a.
b.
c.
d.
one character
one field
one line
the data from the current position to the end of the file
ANS: C
5. When you call the Write method of a binary output stream, you must specify
a. the character to be written
b. the data to be written
c. the record to be written
d. the data type to be written
ANS: B
6. To read data from a binary file, you need to use a FileStream object and a
a. DataReader object
b. CharacterReader object
c. BinaryReader object
d. TextReader object
ANS: C
7. You can call the PeekChar method from a binary input stream to determine
a.
b.
c.
d.
what the data type of the next field is
whether another character exists in the file
whether the directory for the file exists
whether the file is in the specified directory
ANS: B
8. What type of exception can be prevented by using the Exists method of the File class?
a. IOException
c. FileNotFoundExeption
b. EndOfStreamException
d. MethodNotFoundException
ANS: C
9. What type of exception can be prevented by using the Peek method?
a. IOException
b. EndOfStreamException
c. FileNotFoundExeption
d. MethodNotFoundException
ANS: B
10. If a string named path refers to a file that you want to delete, which of the following statements will delete
that file?
a. Directory.Delete(path)
b. File.Delete(path)
c. path.Delete()
d. File.DeleteFile(path)
ANS: B
11. To allow data to flow from a file to an application’s internal memory, the .NET Framework uses
a. an input stream
b. an output stream
c. a text stream
d. a binary stream
ANS: A
12. What namespace does the .NET Framework use to store classes that work with input and output
operations?
a. System.FileIO
b. System.File.IO
c. System.IO
d. System.File
ANS: C
13. If the path variable contains a string that refers to an existing file, what does the following code do?
Dim fs As New FileStream(path, FileMode.OpenOrCreate)
a.
b.
c.
d.
Creates the file but doesn’t open it
Creates the file and then opens it
Opens the file
Opens the file and truncates it so its size is zero bytes
ANS: C
14. If the path variable contains a string that refers to an existing file, what does the following code do?
Dim fs As New FileStream(path, FileMode.Open, FileAccess.Write)
a.
b.
c.
d.
Opens the file so data can be read from it, but not written to it
Opens the file so data can be written to it, but not read from it
Opens the file and only allows other applications to open it for writing
Opens the file and prevents other applications from opening it
ANS: B
15. Assume that you have a valid StreamWriter object named textOut. What does the following code do?
textOut.Write("Wizard of Oz")
textOut.Write(vbTab)
textOut.Write("1939")
textOut.WriteLine()
a.
b.
c.
d.
Writes three strings to a binary file
Writes four strings to a binary file
Writes a record that consists of two tab-delimited fields to a text file
Throws an IOException
ANS: C
16. Assume that you have a valid StreamReader object named textIn. What does the following code do?
Do While textIn.Peek <> -1
Dim row As String = textIn.ReadLine
MessageBox.Show(row)
Loop
a.
b.
c.
d.
Displays the first line of a binary file in a message box
Displays each line of a binary file in successive message boxes
Displays the first line of a text file in a message box
Displays each line of a text file in successive message boxes
ANS: D
17. What type of file is opened in the window below?
a. a text file
b. a binary file
c. a delimited file
d. a console file
ANS: B
18. What type of exception is prevented by the use of the If statement in the Finally block that follows?
Finally
If fileStream IsNot Nothing Then
fileStream.Close()
End If
a. DataException
b. EOFException
c. FileNotFoundExeption
d. NullPointerException
ANS: D
19. If the numbersFile string refers to a file that contains three integers, how many integers will that file
contain when the code that follows is executed?
Dim binaryOut As New BinaryWriter( _
New FileStream(numbersFile, FileMode.Create))
binaryOut.Write(4)
binaryOut.Close()
a. 1
b. 3
c. 4
d. 7
ANS: A
20. What method of the BinaryReader class do you use to read a decimal value from a binary file?
a. Read
b. ReadDecimal
c. ReadDecimal32
d. ReadDecimal64
ANS: B
21. What method of the BinaryReader class do you use to read an integer value from a binary file?
a. Read
b. ReadInteger
c. ReadInt32
d. ReadInt64
ANS: C
22. If dir is a valid directory and lstBox is a list box control, what does the following code do?
For Each item As String in My.Computer.FileSystem.GetFiles(dir)
lstBox.Items.Add(item)
Loop
a.
b.
c.
d.
Lists the contents of the first file in the directory
Lists the name of the first file in the directory
Lists the contents of all the files in the directory
Lists the names of all the files in the directory
ANS: D
Chapter 23: How to work with XML
MULTIPLE CHOICE
1. Which of the following statements is not true about XML?
a.
b.
c.
d.
XML is used by the .NET Framework to store and exchange data.
XML can be used to structure data that’s sent over the Internet.
XML documents can be used as an alternative to text and binary files.
XML consists of a set of pre-defined tags and elements.
ANS: D
2. The first tag in an XML document defines the
a. parent element
b. child element
c. root element
d. XML declaration
ANS: D
3. An end tag for an XML element is identified by
a. a slash (/)
b. a backslash (\)
c. a closing bracket (>)
d. an exclamation point (!)
ANS: A
4. The content for an XML element is coded
a.
b.
c.
d.
between the opening bracket and the closing bracket for the tag
within the start tag for the element
after the end tag for the element
between the start tag and end tag for the element
ANS: D
5. The start tag for an element can contain one or more
a. parameters
b. attributes
c. child elements
d. comments
ANS: B
6. Which of the following is not true when you’re using DataGrid view in the XML Editor window?
a.
b.
c.
d.
The XML document is displayed in the form of a data table.
You can add, modify, and delete data in the XML document without coding tags.
You can modify tags in the XML document.
You can use the Code command in the View window to switch back to XML view
ANS: C
7. When coding attributes for a parent element that contains a large number of child elements, many
designers
a.
b.
c.
d.
use one attribute to store a field that uniquely identifies the parent element
store all of the child elements as attributes
store all child elements that don’t contain additional child elements as attributes
store as many child elements as possible as attributes
ANS: A
8. When using an XmlWriter object to write an XML document, which method or methods can you use to
write a child element that contains content?
a.
b.
c.
d.
WriteStartElement, WriteContent, and WriteEndElement
WriteStartElement, WriteElementValue, and WriteEndElement
WriteElementString
WriteChildElement
ANS: C
9. When you use the XmlReader object to read an XML document, the document is treated as a series of
a. elements
b. attributes
c. nodes
d. records
ANS: C
10. To get the value of an attribute when you’re using an XmlReader object to read an XML document, you
can use the
a.
b.
c.
d.
ReadStartElement, ReadAttributeValue, and ReadEndElement methods
ReadAttribute method
Attribute property
the Item property with a name argument
ANS: D
11. If an XML document is created with indented formatting, you should set a property of the XmlReader
object that’s used to read the file
a.
b.
c.
d.
so the indentation is removed before the elements are read
so indented formatting is assumed
so white space is ignored
so the node types don’t include spaces
ANS: C
Code example 23-1
<?xml version="1.0" encoding="utf-8" ?>
<!--Episode data-->
<Episodes>
<Episode Number="I">
<Title>The Phantom Menace</Title>
<Year>1999</Year>
</Episode>
<Episode Number="II">
<Title>Attack of the Clones</Title>
<Year>2002</Year>
</Episode>
<Episode Number="III">
<Title>Revenge of the Sith</Title>
<Year>2002</Year>
</Episode>
<Episode Number="IV">
<Title>A New Hope</Title>
<Year>1977</Year>
</Episode>
<Episode Number="V">
<Title>The Empire Strikes Back</Title>
<Year>1980</Year>
</Episode>
<Episode Number="VI">
<Title>Return of the Jedi</Title>
<Year>1983</Year>
</Episode>
</Episodes>
12. (Refer to code example 23-1.) How many Episode elements are in this XML document?
a. none
b. 1
c. 6
d. 12
ANS: C
13. (Refer to code example 23-1.) What is the name of the root element for this XML document?
a. ?xml
b. Episode
c. Episodes
d. data
ANS: C
14. (Refer to code example 23-1.) What is the content of the first Year element?
a. Year
b. 1999
c. /Year
d. nothing
ANS: B
15. (Refer to code example 23-1.) What attribute is used in this XML document?
a. Episodes
b. Episode
c. Year
d. Number
ANS: D
16. Which of the following statements is not true?
a.
b.
c.
d.
Attributes can appear in any order within an element.
Attributes are coded within an element tag.
Attributes do not require end tags.
Attributes are more convenient than child elements for long string values.
ANS: D
17. What does the second statement shown below do?
Dim writer As New XmlWriter(path, System.Text.Encoding.UTF8)
writer.Formatting = Formatting.Indented
a. Specifies that the XmlWriter object should use UTF8 formatting
b. Specifies that the XmlWriter object should ignore indentation when it formats the XML
output
c. Specifies that the XmlWriter object should use indentation to format the XML output
d. Specifies that the XmlWriter object should allow attributes to be indented
ANS: C
Chapter 24: How to enhance the user interface
MULTIPLE CHOICE
1. When you use a single-document interface,
a.
b.
c.
d.
only one form can be displayed at a time
the startup form contains all other forms in the application
you can’t switch between the application windows
each form runs in its own application window
ANS: D
2. When you use a multiple-document interface, what type of form contains the other forms?
a. a startup form
b. a child form
c. a parent form
d. a root form
ANS: C
3. The basic purpose of a startup form in a multi-form application with a single-document interface is to
a.
b.
c.
d.
load the code for the other forms
set the properties for the other forms
provide access to the other forms of the application
contain the other forms of the application
ANS: C
4. If tabScenarios is the name of a Tab control with four tabs, which of the following checks if the first tab is
displayed?
a.
b.
c.
d.
If
If
If
If
tabScenarios.SelectedIndex
tabScenarios.SelectedIndex
tabScenarios.SelectedTab =
tabScenarios.SelectedTab =
=
=
0
1
0 Then
1 Then
Then
Then
ANS: C
5. When you design a form that uses menus, you have to write an event handler for the
a. Click event of each menu
b. Click event of each menu item
c. Select event of each menu
d. Select event of each menu item
ANS: B
6. What method do you call from a form object to display the form in a multi-form application?
a. Load
c. ShowChild
b. Show
d. PerformClick
ANS: B
7. If the code that follows is in an event handler for a form, what does it do?
frmCalculator.MDIParent = Me
a.
b.
c.
d.
Sets the form named frmCalculator as the startup form for the project
Sets the form named frmCalculator as the root form for the project
Sets the form named frmCalculator as the parent form of the current form
Sets the form named frmCalculator as a child form of the current form
ANS: D
8. When is this if statement true?
If Me.ActiveMDIChild IsNot Nothing Then
a.
b.
c.
d.
If data has not been entered into an active child form
If data has been entered into an active child form
If there is an active child form
If there is not an active child form
ANS: C
9. If tbMain is a toolbar and mnuToolbar is a menu item, what does the statement that follows do?
tbMain.Visible = mnuToolbar.Checked
a.
b.
c.
d.
Hides the toolbar when the Toolbar menu item is checked
Hides the toolbar when the Toolbar menu item is unchecked
Unchecks the Toolbar menu item when the toolbar is clicked
Synchronizes the display and hiding of the toolbar with the checking and unchecking of
the Toolbar menu item
ANS: D
10. What control must you add to a form if you want to display a brief description of a control on the form
when you place the mouse pointer over it?
a. ToolBar
b. HelpProvider
c. Label
d. ToolTip
ANS: D
11. To display context-sensitive help for a control, the user can move the focus to a control and then
a.
b.
c.
d.
select the Contents command from the Help menu
select the Search command from the Help menu
press the F1 key
right-click on the control and select Dynamic Help from the shortcut menu
ANS: C
12. On a Tab control, what event occurs when the user selects another tab?
a. ButtonClicked
b. TabClicked
c. IndexChanged
d. SelectedIndexChanged
ANS: D
13. What menu item property determines if the menu item is grayed out?
a. Available
b. Visible
c. Enabled
d. Checked
ANS: C
14. What menu item property determines if the menu item is displayed or hidden?
a. Available
b. Visible
c. Enabled
d. Hidden
ANS: B
15. What property do you use to indicate that the current form is the parent form for the application?
a. ActiveMdiParent
b. ParentForm
c. MdiParent
d. IsMdiContainer
ANS: D
16. Which of the following statements arranges all child forms so they’re cascaded?
a. Me.Layout(Cascade)
b. Me.LayoutMdi(MdiLayout.Cascade)
c. Me.LayoutMdi(LayoutMdi.Cascade)
d. Me.Layout(Layout.Cascade)
ANS: B
17. If the mnuExit variable refers to the Exit menu item on the File menu, what does the following statement
do?
mnuExit.PerformClick()
a.
b.
c.
d.
Executes the PerformClick event for the menu item
Executes the Click event for the menu item
Displays the File menu and highlights the Exit menu item
None of the above
ANS: B
18. If you start an application within a Try block in the Main procedure in a module, you can use the Catch
block to catch
a. all errors of the ApplicationError class
b. any errors that aren’t handled by the classes of the application
c. only errors thrown by public procedures in other classes
d. only errors thrown by private procedures in other classes
ANS: B
Chapter 25: How to deploy an application
MULTIPLE CHOICE
1. Which of the following is not a feature of Setup program deployment?
a. It provides for automatic updating of the application.
b. It provides a way to uninstall the application.
c. It creates an icon for the application in the Start menu.
d. It provides a way to install any other files needed by the application.
ANS: A
2. Which of the following is not a weakness of XCopy deployment?
a. It can’t check to make sure that all the required files are installed on the user’s PC.
b. It doesn’t provide for automatic updating of the application.
c. It requires the creation of a release build.
d. It doesn’t provide a way to uninstall the application.
ANS: C
3. When you use ClickOnce deployment, you can publish the application to all but one of the following.
Which one is it?
a. your disk drive
b. the user’s disk drive
c. a network drive
d. a web server
ANS: B
4. By default, ClickOnce deployment provides for automatic updates, and the users are alerted
a. whenever an update becomes available
b. when they start the application and an update is available
c. after they start the application and an update is available
d. only if they check the Update option in the Help menu
ANS: B
5. To create a Setup program for a Windows application, you need to
a. use the Setup wizard
b. use the Setup editors for the application
c. create a Setup project within the solution for the application
ANS: C
6. To add the files that are needed for a Setup program, you can use the
a. File System Editor
c. Launch Conditions Editor
b. File Types Editor
d. Setup Program Editor
ANS: A
7. To distribute a Setup program to the users, you can
a. copy the Release folder to a network server
b. burn the Release folder to a CD
c. both a and b
ANS: C
8. When you’re deploying an application that uses a SQL Server database on a network server, you need to
a. install SQL Server on each user’s machine
b. set the permissions correctly on each user’s machine
c. add the mdf file for the database to the project
d. make sure the connection string is set correctly
ANS: D
Download