California State University, Sacramento
Chapter 19: How to work with inheritance
MULTIPLE CHOICE
1. When used correctly, inheritance can
|a. |make an application run faster |
|b. |make it easier to write the code for the application |
|c. |simplify the overall design of an application |
|d. |eliminate the need for casting |
ANS: C
2. In the System.Windows.Forms namespace, the Control class
|a. |provides properties and methods that all controls in the namespace have in common |
|b. |inherits the properties and methods from all of the control classes in the namespace |
|c. |is the base class for the Button, TextBox, and Label classes, but not the Form class |
|d. |is a child class of the Form class |
ANS: A
3. The ToString, Equals, and GetHashCode methods are available to all objects because
|a. |they are defined in the System namespace |
|b. |they are inherited by the System.Object class, which all other objects are based on |
|c. |they are members of the System.Object class, which all objects inherit |
|d. |they are defined with Public access |
ANS: C
4. A Protected method defined within a base class is available to
|a. |only the base class |
|b. |only classes derived from the base class |
|c. |both the base class and classes derived from it |
|d. |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 |c. |Polymorphism |
|b. |Encapsulation |d. |Hiding |
ANS: C
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. |the GetBirthday method defined in the Person class |
|b. |the GetBirthday method defined in the Student class |
|c. |the GetBirthday method defined in the Object class |
|d. |none of the above |
ANS: B
7. The GetType method of an object returns
|a. |a Type enumeration that identifies the object’s type |
|b. |a Type object that contains information about the object’s type |
|c. |a string that contains the name of the object’s type |
|d. |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. |have only one derived class |
|b. |be the base class for only one derived class |
|c. |be only a base class or a derived class |
|d. |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. |Public New Function CalculateMPG(ByVal s As Integer) As Double |
|b. |Public Overrides Function CalculateMPG(ByVal speed As Integer) As Double |
|c. |Public New Function CalculateMPG(ByVal speed As Double) As Double |
|d. |Public Overrides Function CalculateMPG(ByVal s As Double) As Double |
ANS: D
Diagram 19-1
[pic]
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. |Sailboat |
|b. |Canoe |
|c. |Sailboat and Canoe |
|d. |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 |c. |Automobile and Motorcycle |
|b. |Vehicle and WaterCraft |d. |Vehicle |
ANS: C
13. If a method accepts an Object type, what types of objects can it accept?
|a. |None |
|b. |All objects |
|c. |Only objects created from classes in the System namespace |
|d. |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. |To prevent others from inheriting the class |
|b. |To improve efficiency |
|c. |To prevent others from changing how the methods work |
|d. |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. |An interface can only declare abstract members. |
|b. |An interface can inherit other interfaces. |
|c. |A class can only implement a single interface. |
|d. |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. |any object |
|b. |any object that implements the IWriteable interface |
|c. |any object that implements the Save method |
|d. |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. |implements that interface |
|b. |defines the same methods as the interface |
|c. |implements the interface or defines the same methods as the interface |
|d. |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. |The class that defines the object |
|b. |The interface that the object implements |
|c. |Any subclass of the class that defines the object |
|d. |All of the above |
|e. |A and C only |
ANS: D
9. The ICloneable interface defines a Clone method
|a. |that returns an object type |
|b. |that accepts an object type as a parameter |
|c. |that returns a specific type |
|d. |that accepts a specific type as a parameter |
ANS: A
10. The IComparable() interface defines a CompareTo method
|a. |that returns an object type |
|b. |that accepts an object type as a parameter |
|c. |that returns a specific type |
|d. |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. |you must make sure that the clone refers to a different Customer object |
|b. |you must make sure that the clone refers to the same Customer object |
|c. |you must convert the Customer object to its composite value types |
|d. |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. |stores data with different data types |
|b. |stores data as fields |
|c. |separates each record with a new line character |
|d. |uses input and output streams |
ANS: A
2. Which of the following is not the cause of a common I/O exception?
|a. |The directory can’t be found. |
|b. |The file can’t be found. |
|c. |The program tries to read beyond the end of a stream. |
|d. |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 |c. |RecordReader object |
|b. |StreamReader object |d. |FieldReader object |
ANS: B
4. When you use a method to read data from a text file, you normally read
|a. |one character |
|b. |one field |
|c. |one line |
|d. |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 |c. |the record to be written |
|b. |the data 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 |c. |BinaryReader object |
|b. |CharacterReader object |d. |TextReader object |
ANS: C
7. You can call the PeekChar method from a binary input stream to determine
|a. |what the data type of the next field is |
|b. |whether another character exists in the file |
|c. |whether the directory for the file exists |
|d. |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 |c. |FileNotFoundExeption |
|b. |EndOfStreamException |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) |c. |path.Delete() |
|b. |File.Delete(path) |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 |c. |a text stream |
|b. |an output 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 |c. |System.IO |
|b. |System.File.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. |Creates the file but doesn’t open it |
|b. |Creates the file and then opens it |
|c. |Opens the file |
|d. |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. |Opens the file so data can be read from it, but not written to it |
|b. |Opens the file so data can be written to it, but not read from it |
|c. |Opens the file and only allows other applications to open it for writing |
|d. |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. |Writes three strings to a binary file |
|b. |Writes four strings to a binary file |
|c. |Writes a record that consists of two tab-delimited fields to a text file |
|d. |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. |Displays the first line of a binary file in a message box |
|b. |Displays each line of a binary file in successive message boxes |
|c. |Displays the first line of a text file in a message box |
|d. |Displays each line of a text file in successive message boxes |
ANS: D
17. What type of file is opened in the window below?
[pic]
|a. |a text file |c. |a delimited file |
|b. |a binary 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 |c. |FileNotFoundExeption |
|b. |EOFException |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 |c. |4 |
|b. |3 |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 |c. |ReadDecimal32 |
|b. |ReadDecimal |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 |c. |ReadInt32 |
|b. |ReadInteger |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 puter.FileSystem.GetFiles(dir)
lstBox.Items.Add(item)
Loop
|a. |Lists the contents of the first file in the directory |
|b. |Lists the name of the first file in the directory |
|c. |Lists the contents of all the files in the directory |
|d. |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. |XML is used by the .NET Framework to store and exchange data. |
|b. |XML can be used to structure data that’s sent over the Internet. |
|c. |XML documents can be used as an alternative to text and binary files. |
|d. |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 |c. |root element |
|b. |child element |d. |XML declaration |
ANS: D
3. An end tag for an XML element is identified by
|a. |a slash (/) |c. |a closing bracket (>) |
|b. |a backslash (\) |d. |an exclamation point (!) |
ANS: A
4. The content for an XML element is coded
|a. |between the opening bracket and the closing bracket for the tag |
|b. |within the start tag for the element |
|c. |after the end tag for the element |
|d. |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 |c. |child elements |
|b. |attributes |d. |comments |
ANS: B
6. Which of the following is not true when you’re using DataGrid view in the XML Editor window?
|a. |The XML document is displayed in the form of a data table. |
|b. |You can add, modify, and delete data in the XML document without coding tags. |
|c. |You can modify tags in the XML document. |
|d. |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. |use one attribute to store a field that uniquely identifies the parent element |
|b. |store all of the child elements as attributes |
|c. |store all child elements that don’t contain additional child elements as attributes |
|d. |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. |WriteStartElement, WriteContent, and WriteEndElement |
|b. |WriteStartElement, WriteElementValue, and WriteEndElement |
|c. |WriteElementString |
|d. |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 |c. |nodes |
|b. |attributes |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. |ReadStartElement, ReadAttributeValue, and ReadEndElement methods |
|b. |ReadAttribute method |
|c. |Attribute property |
|d. |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. |so the indentation is removed before the elements are read |
|b. |so indented formatting is assumed |
|c. |so white space is ignored |
|d. |so the node types don’t include spaces |
ANS: C
Code example 23-1
The Phantom Menace
1999
Attack of the Clones
2002
Revenge of the Sith
2002
A New Hope
1977
The Empire Strikes Back
1980
Return of the Jedi
1983
12. (Refer to code example 23-1.) How many Episode elements are in this XML document?
|a. |none |c. |6 |
|b. |1 |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 |c. |Episodes |
|b. |Episode |d. |data |
ANS: C
14. (Refer to code example 23-1.) What is the content of the first Year element?
|a. |Year |c. |/Year |
|b. |1999 |d. |nothing |
ANS: B
15. (Refer to code example 23-1.) What attribute is used in this XML document?
|a. |Episodes |c. |Year |
|b. |Episode |d. |Number |
ANS: D
16. Which of the following statements is not true?
|a. |Attributes can appear in any order within an element. |
|b. |Attributes are coded within an element tag. |
|c. |Attributes do not require end tags. |
|d. |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. |only one form can be displayed at a time |
|b. |the startup form contains all other forms in the application |
|c. |you can’t switch between the application windows |
|d. |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 |c. |a parent form |
|b. |a child 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. |load the code for the other forms |
|b. |set the properties for the other forms |
|c. |provide access to the other forms of the application |
|d. |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. |If tabScenarios.SelectedIndex = 0 Then |
|b. |If tabScenarios.SelectedIndex = 1 Then |
|c. |If tabScenarios.SelectedTab = 0 Then |
|d. |If tabScenarios.SelectedTab = 1 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 |c. |Select event of each menu |
|b. |Click event of each menu item |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. |Sets the form named frmCalculator as the startup form for the project |
|b. |Sets the form named frmCalculator as the root form for the project |
|c. |Sets the form named frmCalculator as the parent form of the current form |
|d. |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. |If data has not been entered into an active child form |
|b. |If data has been entered into an active child form |
|c. |If there is an active child form |
|d. |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. |Hides the toolbar when the Toolbar menu item is checked |
|b. |Hides the toolbar when the Toolbar menu item is unchecked |
|c. |Unchecks the Toolbar menu item when the toolbar is clicked |
|d. |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 |c. |Label |
|b. |HelpProvider |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. |select the Contents command from the Help menu |
|b. |select the Search command from the Help menu |
|c. |press the F1 key |
|d. |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 |c. |IndexChanged |
|b. |TabClicked |d. |SelectedIndexChanged |
ANS: D
13. What menu item property determines if the menu item is grayed out?
|a. |Available |c. |Enabled |
|b. |Visible |d. |Checked |
ANS: C
14. What menu item property determines if the menu item is displayed or hidden?
|a. |Available |c. |Enabled |
|b. |Visible |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 |c. |MdiParent |
|b. |ParentForm |d. |IsMdiContainer |
ANS: D
16. Which of the following statements arranges all child forms so they’re cascaded?
|a. |Me.Layout(Cascade) |c. |Me.LayoutMdi(LayoutMdi.Cascade) |
|b. |Me.LayoutMdi(MdiLayout.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. |Executes the PerformClick event for the menu item |
|b. |Executes the Click event for the menu item |
|c. |Displays the File menu and highlights the Exit menu item |
|d. |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
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- home department of computer science
- linear search program in c
- powerpoint practice actvities
- assignment 1 sorting with binary search tree due by 11
- 3 university of florida
- programming assignment 4 binary trees
- california state university sacramento
- mips assembly language programming
- task 1 getting it homepage ark acton academy