SEN632 Java UML C++ Software Architecture Application - Exam Prep - Part One.txt

Card Set Information

Author:
caldreaming
ID:
289185
Filename:
SEN632 Java UML C++ Software Architecture Application - Exam Prep - Part One.txt
Updated:
2014-11-14 15:24:17
Tags:
java javascript applet plus software object oriented javax servlet program programming UML unified modeling language mvc model view controller
Folders:

Description:
An in-depth study of software architecture. Defines and discusses object-oriented design, modeling and programming at an advanced level using UML. An advanced study of a standard implementation of a distributed, object-oriented middleware technology (e.g., J2EE, Microsoft.NET, etc. ). Students design and implement an architecture using modern technologies such as J2EE, .NET.
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user caldreaming on FreezingBlue Flashcards. What would you like to do?


  1. Instance variables are also known as;

    A) local variables
    B) fields
    C) Both b and c
    D) instances variable
    C) Both b and c.

    Instance variables are also known as fields.  Instance variables are declared in classes and are typically manipulated by the methods of the class they belong to.  Each object of a class maintains a separate instance of these kinds of variables.
    (this multiple choice question has been scrambled)
  2. Variables declared in the body of a method are known as; 

    A) local variables
    B) instances variable
    C) fields
    D) Both b and c
    A) local variables

    Variables that are declared within the body of a method are known as local variables.
    (this multiple choice question has been scrambled)
  3. In general, it is best to make __________ private and _______________ public in order to incorporate data hiding.

    A) methods, local variables
    B) instance variables, fields
    C) methods, instance variables
    D) instance variables, methods
    D) instance variables, methods

    Precede each field and method declaration with an access modifier.  Generally, instance variables should be declared private and methods public.  In some cases it is also appropriate to make methods private in cases where they are only used by other methods of the same class.
    (this multiple choice question has been scrambled)
  4. There are 3 ways to return control to a statement that calls a method.  What are they?
    • 1. Right brace at end of method when no return is required (void)
    • 2. return; statement is encountered
    • 3. return expression; statement is encountered
  5. True/False:  By default, the compiler provides a default constructor with no parameters in any class that does not explicitly include a constructor.
    True.

    By default, the compiler provides a default constructor with no parameters in any class that does not explicitly include a constructor.    When this happens, all of the instance variables are set to a default value.
  6. True/False:  In Java it is possible to have many classes in every .java file.
    False.

    You can only have one public class in each Java file.
  7. Method headers contain all of the following except:       

    A) Access modifier       
    B) Left brace       
    C) Name of method       
    D) Return type
    B) Left brace 

    Every method body is is delimited by left and right braces.
    (this multiple choice question has been scrambled)
  8. Every Java application is composed of at least one:       

    A) public class declaration       
    B) local variable       
    C) instance variable       
    D) imported class
    A) public class declaration

    (textbook page 40)
    (this multiple choice question has been scrambled)
  9. A class instance creation expression contains:  
         
    a) Parentheses       
    b) The new keyword       
    c) The name of the class       
    d) All of the above
    d) All of the above

    (Textbook page 74 & 86)
  10. Calling a method of another object requires which item?       

    A) The new keyword       
    B) The dot separator       
    C) Open and close braces       
    d) None of the above
    B) The dot separator
    (this multiple choice question has been scrambled)
  11. What is the default initial value of a String instance variable?       

    A) "default"       
    B) null
    C) default       
    D) ""       
    B) null

    (textbook page 82)
    (this multiple choice question has been scrambled)
  12. Each class declaration that begins with the keyword ________ must be stored in a file that has exactly the the same name and ends with the .java file extension.
    public
  13. Keyword __________ in a class declaration is followed immediately by a classes name.
    class
  14. Keyword __________ requests memory from the system to store an object, then calls the corresponding class's constructor to initialize the object.
    new
  15. Each parameter must specify both a __________ and a ____________.
    Each parameter must specify both a ____type___   and a _____name_____.
  16. By default, classes that are compiled in the same directory are considered to be in the same package known as the _____________________.
    default package

    By default, classes that are compiled in the same directory are considered to be in the same package known as the _default_package_______.
  17. When each object of a class maintains its own copy of an attribute, the field that represents the attribute is also known as a __________________.
    instance variable

    When each object of a class maintains its own copy of an attribute, the field that represents the attribute is also known as a _instance_variable_.
  18. Java provides two primitive types for storing floating-point numbers in memory; ____________  and ____________.
    float, double

    Java provides two primitive types for storing floating-point numbers in memory; _float_  and _double___.
  19. Variables of type double represent __________ floating-point numbers.
    double-precision

    Variables of type double represent _double-precision__ floating-point numbers.
  20. Scanner method ______________ returns a double value.
    nextDouble

    Scanner method _nextDouble__ returns a double value.
  21. Keyword public is an access ___________.
    modifier

    Keyword public is an access _modifier__.
  22. Return type ____________ indicates that a method will not return a value.
    void

    Return type _void__ indicates that a method will not return a value.
  23. Scanner method ____________ reads characters until it encounters a newline character, then returns those characters as a string.
    nextLine

    Scanner method _nextLine__ reads characters until it encounters a newline character, then returns those characters as a string.
  24. Class string is in package _________________.
    java.lang

    Class string is in package _java.lang___.
  25. An _________________________ is not required if you always refer to a class with it's fully qualified class name.
    import declaration

    An _import declaration__ is not required if you always refer to a class with it's fully qualified class name.
  26. A _________________________ is a number with a decimal point, such as 7.33, 0.0975 or 1000.12345.
    floating-point number

    A _floating-point_number__ is a number with a decimal point, such as 7.33, 0.0975 or 1000.12345.
  27. Variables of type float represent _________________ floating-point numbers.
    single-precision

    Variables of type float represent _single-precision__ floating-point numbers.
  28. The format specifier ______________________ is used to output values of type float or type double.
    %f

    The format specifier ____%f___ is used to output values of type float or type double.
  29. Types in Java are divided into two categories; ____________ types and ______________ types.
    primitive, reference

    Types in Java are divided into two categories; _primitive_ types and _reference_ types.
  30. What is the difference between a local variable and a field?
    Local variables are declared within methods while fields (also known as instance variables) are declared within classes.  A local variable can only be used within the method where it is declared while an instance variable is available to all methods within the class in which it is declared.
  31. True/False:   By convention, method names begin with an uppercase first letter.
    False.  By convention, method names begin with a lowercase first letter and then use 'camel back' form where all subsequent words in the name begin with a capital first letter such as; nextLine.
  32. True/False:   An import declaration is not required when one class in a package uses another in the same package.
    True.

    Classes within the same package can implicitly call each other without imports.
  33. True/False:   Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform it's task.
    True
  34. True/False:   Variables or methods declared with access modifier private are accessible only to methods of the class in which they're declared.
    True
  35. True/False:   A primitive-type variable can be used to invoke a method.
    False

    • A primitive-type variable cannot be used to invoke a method.  A reference to an object is required to invoke the objects methods as in;
    • GradeBook myGradeBook = new GradeBook();   Where myGradeBook is a reference variable that refers to a GradeBook object.  (Textbook page 84).
  36. True/False:   Variables declared in the body of a particular method are known as instance variables and can be used in all methods of the class.
    False

    Such variables declared in the body of a method are called local variables however they can only be used within the method in which they are declared.
  37. True/False:   Every methods body is delimited by left and right curly braces {}.
    True

    The method body is delimited by the left and right curly brace {}. Method headers contain an access modifier, the name of the method and a Return type.  The curly braces are not considered to be part of the method header.
  38. True/False:  Primitive type local variables are initialized by default.
    False

    Primitive type instance variables are initialized by default. Each local variable must be explicitly assigned a value.
  39. True/False:  Reference-type instance variables are initialized by default to the value null.
    True
  40. True/False:  Any class that contains; public static void main(String[] args) can be used to execute an application.
    True
  41. True/False:  The number of arguments in the method call must match the number of parameters in the method declarations parameter list.
    True
  42. True/False:  Floating-point values that appear in source code are known as floating-point literals and are type float by default.
    False

    • Such literals are of type double by default. 
    • (Textbook page 88).
  43. A method is invoked with a _________________.
    method call

    A method is invoked with a _method_call_.
  44. A variable known only within the method in which it is declared is called a __________________.
    local variable

    A variable known only within the method in which it is declared is called a _local_variable__.
  45. The ______________ statement in a call method can be used to pass the value of an expression back to the calling method.
    return 

    The _return_ statement in a call method can be used to pass the value of an expression back to the calling method.
  46. The keyword _______________ indicates that a method does not return a value.
    void

    The keyword _void__ indicates that a method does not return a value.
  47. Data can be added or removed only from the _______________ of a stack.
    top

    Data can be added or removed only from the _top__ of a stack.
  48. Stacks are known as ___________________ data structures.
    LIFO  Last-In, First-out

    Stacks are known as _last-in,_first-out_(LIFO)_ data structures; the last item pushed (inserted) on the stack is the first item popped (removed) from the stack.
  49. The three ways to return control from a called method to a caller are ______________, ___________________ and ________________.
    return; or return expression; or encountering the closing right brace of a method. 

    The three ways to return control from a called method to a caller are _return;_, __return_expression;__ and _encountering_the_closing_right_brace_of_a_method_.
  50. An object of class ____________ produces random numbers.
    Random

    An object of class _Random__ produces random numbers.
  51. The program-execution stack contains the memory for local variables on each invocation of a method during a program's execution.  This data, stored as a portion of the program-execution stack, is known as the ____________ or ______________ of the method call.
    activation record or stack frame

    The program-execution stack contains the memory for local variables on each invocation of a method during a program's execution.  This data, stored as a portion of the program-execution stack, is known as the _activation_record_ or _stack_frame_ of the method call.
  52. If there are more method calls than can be stored on the program-execution stack, an error known as a ______________________ occurs.
    stack overflow

    If there are more method calls than can be stored on the program-execution stack, an error known as a _stack_overflow_ occurs.
  53. The _________________ of a declaration is the portion of a program that can refer to the entity in the declaration by name.
    scope

    • The _scope_ of a declaration is the portion of a program that can refer to the entity in the declaration by name.
    • (Textbook page 219-220).
  54. It's possible to have several methods with the same name that each operate on different types or numbers of arguments.  This feature is called method _____________.
    overloading

    • It's possible to have several methods with the same name that each operate on different types or numbers of arguments.  This feature is called method _overloading_.
    • (Textbook Page 222).
  55. The program execution-stack is also referred to as the _____________ stack.
    method call

    The program execution-stack is also referred to as the _method_call_ stack.
  56. Lists and tables of values can be stored in _________________.
    arrays

    Lists and tables of values can be stored in _arrays_.
  57. An array is a group of ________________ (called elements or components) containing values that all have the same ______________.
    variables, type

    An array is a group of _variables_ (called elements or components) containing values that all have the same _type_.
  58. The ______________ allows you to iterate through the elements in n array without using  counter.
    enhanced for statement

    • The _enhanced_for_statement_ allows you to iterate through the elements in n array without using  counter. 
    • ie; for (parameter : arrayName)
    •                      statement
    • (Textbook page 258).
  59. The number used to refer to a particular array element is called the element's ______________.
    index

    The number used to refer to a particular array element is called the element's _index_.
  60. An array that uses two indices is referred to as a _________________ array.
    two dimensional

    An array that uses two indices is referred to as a _two_dimensional_ array.
  61. Use the enhanced for statement ____________________ to walk through double array numbers.
    for (double d : numbers)

    Use the enhanced for statement _for_(double_d_:_numbers)_ to walk through double array numbers.
  62. Command-line arguments are stored in _______________.
    an array of Strings, called args by convention

    Command-line arguments are stored in _an_array_of_Strings,_called_args_by_convention_.
  63. Use the expression ___________________ to receive the total number of arguments in a command line. Assume that the command line arguments are stored in String[] args.
    args.length

    Use the expression _args.length_ to receive the total number of arguments in a command line. Assume that the command line arguments are stored in String[] args.
  64. Given the command java MyClass test, the first command-line argument is __________________.
    test

    Given the command java MyClass test, the first command-line argument is _test_.
  65. An __________ in the parameter list of a method indicates that the method can receive a variable number of arguments.
    ellipsis (...)

    An _ellipsis_(...)_ in the parameter list of a method indicates that the method can receive a variable number of arguments.
  66. True/False:  An array can store many different types of values.
    False.

    An array can only store values of the same type.
  67. True/False:  An array index should normally be of type float.
    False

    An array index must be an integer or an integer expression.
  68. True/False:  An individual array element that's passed to a method and modified in that method will contain the modified value when the called method completes execution.
    False for individual primitive-type elements of an array.

    A called method receives and manipulates a copy of the value of such an element, so modifications do not affect the original value. If the reference of an array is passed to a method, however, modifications to the array elements made in the called method are indeed reflected in the original.
  69. True/False:  Command-line arguments are separated by commas.
    False

    Command-line arguments are separated by white space.
  70. Collections of related data items are known as _______________________.
    data structures

    Collections of related data items are known as _data_structures_.

    (Textbook page 241).
  71. ArrayLists are similar to arrays but provide additional functionality such as ______________________.
    dynamic resizing

    ArrayLists are similar to arrays but provide additional functionality such as _dynamic_resizing_.
  72. Arrays are objects so they are considered __________________ types.
    reference

    Arrays are objects so they are considered _reference_ types.

    (Textbook page 242)
  73. When compiling a class in a package, the javac command-line option ______________ specifies where to store the package and causes the compiler to create the package's directories if they do not exist.
    -d

    When compiling a class in a package, the javac command-line option _-d_ specifies where to store the package and causes the compiler to create the package's directories if they do not exist.
  74. String class static method ________________ is similar to method System.out.printf, but returns a formatted String rather than displaying a String in a command window.
    format

    String class static method _format_ is similar to method System.out.printf, but returns a formatted String rather than displaying a String in a command window.

    (TextBook Page 314).
  75. If a method contains a local variable with the same name as one of it's class's fields, the local variable ______________ the field in that method's scope.
    shadows

    If a method contains a local variable with the same name as one of it's class's fields, the local variable _shadows_ the field in that method's scope.
  76. The _____________ method is called by the garbage collector just before it reclaims an object's memory.
    finalize

    The _finalize_ method is called by the garbage collector just before it reclaims an object's memory.
  77. A _______________ declaration specifies one class to import.
    single-type import

    A _single-type_import_ declaration specifies one class to import.
  78. If a class declares constructors, the compiler will not create a _________________.
    default constructor

    If a class declares constructors, the compiler will not create a _default_constructor_.
  79. An object's _________________ method is called implicitly when an object appears in code where a String is needed.
    toString

    An object's _toString_ method is called implicitly when an object appears in code where a String is needed.

    (Textbook page 314).
  80. Get methods are commonly called _________ or ____________.
    accessor methods, query methods

    Get methods are commonly called _accessor_methods_ or _query_methods_.
  81. A _______________ method tests whether a condition is true or false.
    predicate

    A _predicate_ method tests whether a condition is true or false.
  82. For every enum, the compiler generates a static method called __________________ that returns an array of the enum's constants in the order in which they were declared.
    values

    For every enum, the compiler generates a static method called _values_ that returns an array of the enum's constants in the order in which they were declared.
  83. Composition is sometimes referred to as an ______________ relationship.
    has-a

    Composition is sometimes referred to as an _has-a_ relationship.  

    It should be noted that in some textbooks this 'has-a' relationship is referred to as 'is-like' relationship.  The other kind of relationship in Java is the 'is-a' relationship.
  84. An _____________________ declaration contains a comma-separated list of constants.
    enum

    An _enum_ declaration contains a comma-separated list of constants.
  85. A _________________ variable represents classwide information that' shared by all the objects of the class.
    static

    A _static_ variable represents classwide information that' shared by all the objects of the class.
  86. A _____________________ declaration imports one static member.
    single static import

    A _single_static_import_ declaration imports one static member.
  87. The _________________________________ states that code should be granted only the amount of privilege and access it that it needs to accomplish it's designated task.
    principle of least privilege

    The _principle_of_least_privilege_ states that code should be granted only the amount of privilege and access it that it needs to accomplish it's designated task.
  88. Keyword ______________ specifies that a variable is not modifiable.
    final

    Keyword _final_ specifies that a variable is not modifiable.
  89. There can be only one _____________________ in a Java source-code file, and it must precede all over declarations and statements in that file.
    package declaration

    There can be only one _package_declaration_ in a Java source-code file, and it must precede all other declarations and statements in that file.
  90. A _________________ declaration imports only the classes that the program uses from a particular package.
    type-import-on-demand

    A _type-import-on-demand_ declaration imports only the classes that the program uses from a particular package.
  91. The compiler uses a ___________________ to locate the classes it needs in it's classpath.
    class loader

    The compiler uses a _class_loader_ to locate the classes it needs in it's classpath.
  92. The classpath for the compiler and JVM can be specified with the _________________ option to the javac or java command, or by setting the ______________ environment variable.
    -classpath, CLASSPATH

    The classpath for the compiler and JVM can be specified with the _-classpath_ option to the javac or java command, or by setting the _CLASSPATH_ environment variable.
  93. Set methods are commonly called _____________________ because they typically change a value.
    mutator methods

    Set methods are commonly called _mutator_methods_ because they typically change a value.
  94. A ___________________ imports all static members of a class.
    static import on demand

    A _static_import_on_demand_ imports all static members of a class.
  95. The public methods of a class are also known as the class's __________________ or ________________.
    public services, public interface

    The public methods of a class are also known as the class's _public_services_ or _public_interface_.

    (Textbook Page 312).
  96. Classes simplify programming, because the client can use only the __________________ methods exposed by the class.
    public

    Classes simplify programming, because the client can use only the _public_ methods exposed by the class. Such methods are usually client oriented rather than implementation oriented.  Clients are neither aware of, nor involved in, a class's implementation. Clients generally care about what a class does and not how it does it. 

    (Textbook page 316).
  97. An attempt by a method that's not a member of a class to access a private member of that class is called a _______________________.
    compilation error

    An attempt by a method that's not a member of a class to access a private member of that class is called a _compilation_error_.

    (Textbook page 317).
  98. The company that popularized personal computing was _________________.
    Apple

    The company that popularized personal computing was _Apple_.
  99. The computer that made personal computing legitimate in business and industry was the _____________________.
    IBM Personal Computer

    The computer that made personal computing legitimate in business and industry was the _IBM_Personal_Computer_.
  100. Computers process data under the control of sets of instructions called __________________.
    programs

    Computers process data under the control of sets of instructions called _programs_.
  101. The key logical units of the computer are the ________, ________, __________, ________, _________ and _________.
    input unit, output unit, memory unit, central processing unit, arithmetic and logic unit, secondary storage unit 

    The key logical units of the computer are the _input_unit_, _output_unit_, _memory_unit, _central_processing_unit_, _arithmetic_and_logic_unit_ and _secondary_storage_unit_.
  102. The three types of languages discussed in chapter one are _____________, ____________ and ______________.
    machine language, assembly languages, high-level languages

    The three types of languages discussed in chapter one are _machine_language_, _assembly_languages_ and _high-level_languages_.
  103. The programs that translate high-level language programs into machine language are called __________________.
    compilers

    The programs that translate high-level language programs into machine language are called _compilers_.
  104. ________________ is a smartphone operating system based on the Linux kernel and Java.
    Android

    _Android_ is a smartphone operating system based on the Linux kernel and Java.
  105. ____________ software is generally feature complete and (supposedly) bug-free, and ready for use by the community.
    release candidate

    _Release_candidate_ software is generally feature complete and (supposedly) bug-free, and ready for use by the community.
  106. The Wii remote, as well as many smartphones, use an ________________ which allows the device to respond to motion.
    accelerometer

    The Wii remote, as well as many smartphones, use an _accelerometer_ which allows the device to respond to motion.
  107. The ____________ command from the JDK executes a Java application.
    java

    The _java_ command from the JDK executes a Java application.
  108. The ____________ command from the JDK compiles a Java program.
    javac

    The _javac_ command from the JDK compiles a Java program.
  109. A java program file must end with the _____________ file extension.
    .java

    A java program file must end with the _.java_ file extension.
  110. When a Java program is compiled, the file produced by the compiler ends with the _____________ file extension.
    .class

    When a Java program is compiled, the file produced by the compiler ends with the _.class_ file extension.
  111. The file produced by the Java compiler contains __________________ that are executed by the Java Virtual Machine (JVM).
    bytecodes

    The file produced by the Java compiler contains _bytecodes_ that are executed by the Java Virtual Machine (JVM).
  112. Objects have the property of _______________________ - although objects may know how to communicate with one another across well-defined interfaces, they normally are not allowed to know how other objects are implemented.
    information hiding

    Objects have the property of _information_hiding_ - although objects may know how to communicate with one another across well-defined interfaces, they normally are not allowed to know how other objects are implemented. 

    (Information hiding is also known as data hiding or encapsulation).
  113. The property of encapsulation is also known as __________________ or _________________.
    information hiding, data hiding

    The property of encapsulation is also known as _information_hiding_ or _data_hiding_.

    (Textbook page 81).
  114. Java programmers concentrate on creating ____________________, which contain fields and the set of methods that manipulate those fields and provide services to clients.
    classes

    Java programmers concentrate on creating _classes_, which contain fields and the set of methods that manipulate those fields and provide services to clients.
  115. The process of analyzing and designing a system from an object-oriented point of view is called _____________________.
    OOAD  Object Oriented Analysis and Design

    The process of analyzing and designing a system from an object-oriented point of view is called _OOAD,_Object_Oriented_Analysis_and_Design_.
  116. In a class containing methods with the same name, the methods are distinquished by;

    Number of arguments
    Types of arguments
    Return type
    Number of arguments and Types of arguments
    Types of arguments and Return type
    Number of arguments and Types of arguments

    (Textbook page 222)
  117. Consider the following Java statements: 

    int x = 9;
    double y = 5.3;
    result = calculateValue( x, y );

    Which of the following statements is true? 

    A. x and y are arguments.
    B. x and y are parameters.
    C. A method is called with its name and parentheses.
    D. Copies of x and y are passed to the method calculateValue().
    a. None of the statements are true.
    b. B and D are true.
    c. B is false.
    d. All of the statements are true.
    D. B is false.

    x and y are arguments. Parameters specified in a method's declaration. They indicate the types of the arguments passed to the method when it is called.
    (this multiple choice question has been scrambled)
  118. A JButton can cause an event (i.e., a call to an event-handling method) if:

    A. The registered event handler implements the ActionListener interface.
    B. An event handler has been called.
    C. The registered event handler extends the GUI.
    D. The JButton has been added to JApplet.
    A. The registered event handler implements the ActionListener interface.
    (this multiple choice question has been scrambled)
  119. Which of these statements best defines scope?

    A. Scope refers to the classes that have access to a variable.
    B. Scoping allows the programmer to use a class without using its fully qualified name.
    C. Scope is the portion of a program that can refer to an entity by name.
    D. Scope determines whether a variable’s value can be altered.
    C. Scope is the portion of a program that can refer to an entity by name.
    (this multiple choice question has been scrambled)
  120. Which of the following does not contribute to improved software reusability?

    * Quickly creating new class libraries without testing them thoroughly
    * Licensing schemes and protection mechanisms
    * Descriptions of classes that allow programmers to determine whether a class fits their needs
    * Cataloging schemes and browsing mechanisms
    My initial guess: * Licensing schemes and protection mechanisms

    But remember that I got 3 out of 5 wrong so at least 3 of my answers are the wrong one.
  121. Information is passed to a method in: 

    A. that method's return.
    B. the arguments to the method.
    C. the method name.
    D. the called method.
    B. the arguments to the method.
    (this multiple choice question has been scrambled)
  122. Programs designed for maintainability are constructed from small simple pieces or modules. Modules in Java are called:

    A. arguments.
    B. both methods and classes.
    C. methods.
    D. classes.
    B. both methods and classes.
    (this multiple choice question has been scrambled)
  123. A well-designed method;

    A. performs a single, well-defined task.
    B. performs multiple unrelated tasks.
    C. repeats code found in other methods.
    D. contains thousands of lines of code.
    A. performs a single, well-defined task.
    (this multiple choice question has been scrambled)
  124. Which of the following methods is not in the Math class?

    A. parseInt
    B. log
    C. ceil
    D. abs
    A. parseInt

    parseInt is in the Integer class.
    (this multiple choice question has been scrambled)
  125. Which of the following can be an argument in a method?

    a. Constants.
    b. Variables.
    c. Expressions.
    d. All of the above.
    d. All of the above.
  126. Method log takes the logarithm of its argument with respect to what base?

    A. pi
    B. e
    C. 2
    D. 10
    B. e
    (this multiple choice question has been scrambled)
  127. Swing GUI components typically are attached to;

    A. an init method.
    B. a JTextArea.
    C. a JApplet.
    D. a content pane.
    D. a content pane.
    (this multiple choice question has been scrambled)
  128. Variables should be declared as fields if;

    A. their values must be saved between calls to the method.
    B. they are arguments.
    C. they are used only within a method.
    D. they are local variables. 
    A. their values must be saved between calls to the method.
    (this multiple choice question has been scrambled)
  129. Which of the following tasks cannot be performed using an enhanced for loop?

    A. displaying all even element values in an array
    B. incrementing the value stored in each element of the array
    C. multiplying all the values in an array together
    D. comparing the elements in an array to a specific value
    B. incrementing the value stored in each element of the array
    (this multiple choice question has been scrambled)
  130. The parameter list in the method header and the method call arguments must agree in:

    a. number
    b. type
    c. order
    d. all of the above
    d. all of the above
  131. Which of the following promotions of primitive types is NOT allowed to occur?

    A. short to long.
    B. double to float.
    C. char to int.
    D. int to double.
    B. double to float.
    (this multiple choice question has been scrambled)
  132. Which of the following primitive types is never promoted to another type?

    A. byte.
    B. boolean.
    C. Both a (double) and c. (boolean)
    D. double.
    C. Both a (double) and c. (boolean)
    (this multiple choice question has been scrambled)
  133. Which statement is not true.

    A. The Java API consists of packages.
    B. The Java API consists of import declarations.
    C. The class javax.swing.JApplet is part of the Java API.
    D. The Java API is provided to keep programmers from "reinventing the wheel."
    B. The Java API consists of import declarations. (The Java API is built from packages.)
    (this multiple choice question has been scrambled)
  134. Which of the following is not a package in the Java API?

    A. java.lang.
    B. java.awt.
    C. javax.swing.event.
    D. java.component.
    D. java.component.
    (this multiple choice question has been scrambled)
  135. The java.text package contains classes for manipulating all of the following items except;

    A. strings
    B. characters
    C. classes
    D. numbers
    C. classes
    (this multiple choice question has been scrambled)
  136. Which statement below could be used to simulate the outputs of tossing a quarter to get heads or tails?

    A. 1 + (int) ( Math.random() * 2 );
    B. 1 + (int) ( Math.random() * 25 );
    C. 1 + (int) ( Math.random() * 6 );
    D. 6 + (int) ( Math.random() * 1 );
    A. 1 + (int) ( Math.random() * 2 );
    (this multiple choice question has been scrambled)
  137. The purpose of (int) in the statement
    1 + (int) (Math.random() * 6);

    A. is to be a scaling factor.
    B. is to truncate the floating-point part of the product.
    C. is to create an element of chance.
    D. is to shift the output value.
    B. is to truncate the floating-point part of the product.
    (this multiple choice question has been scrambled)
  138. Method random generates a random double value in the range from 0.0;

    A. up to and including 100.0
    B. up to and including 1.0
    C. up to but not including 100.0
    D. up to but not including 1.0
    D. up to but not including 1.0
    (this multiple choice question has been scrambled)
  139. An applet's content pane may be assigned a layout manager to:

    A. Arrange GUI components.
    B. Create GUI components.
    C. Implement interfaces.
    D. Handle events.
    A. Arrange GUI components.
    (this multiple choice question has been scrambled)
  140. Which of the following is false?

    A. A static method must be used to access private static instance variables
    B. A static method has no this reference
    C. A static method can call instance methods directly
    D. A static method can be accessed even when no objects of its class have been instantiated
    C. A static method can call instance methods directly
    (this multiple choice question has been scrambled)
  141. What keyword declares that a variable is a constant?

    A. private
    B. static
    C. final
    D. constant
    C. final
    (this multiple choice question has been scrambled)
  142. Identifiers in Java have ________ and ________ scopes?

    A. class, block.
    B. block, statement.
    C. method, class.
    D. statement, file.
    A. class, block.
    (this multiple choice question has been scrambled)
  143. Which of the following statements describes block scope?

    A. It is valid for one statement only.
    B. It begins at the opening { of the class declaration and terminates at the closing }
    C. It limits label scope to only the method in which it is declared.
    D. It begins at the identifier's declaration and ends at the terminating right brace (}).
    D. It begins at the identifier's declaration and ends at the terminating right brace (}).
    (this multiple choice question has been scrambled)
  144. Java programmers do not focus on:

    a. Crafting new classes and reusing existing classes
    b.  Understanding class library implementations
    c. Carefully testing classes they design
    d. Carefully documenting classes they design
    My guess: b.  Understanding class library implementations
  145. The key methods of the class JApplet are:

    A. init, start, paint, stop, destroy, restart.
    B. init, start, paint, stop, destroy, quit.
    C. init, start, repaint, stop, destroy.
    D. init, start, paint, stop, destroy.
    D. init, start, paint, stop, destroy.
    (this multiple choice question has been scrambled)
  146. The repaint method is necessary because:

    A. paint can only be called from init.
    B. repaint provides context (i.e. a Graphics argument) to paint.
    C. paint can only be called once.
    d.None of the above.
    B. repaint provides context (i.e. a Graphics argument) to paint.
    (this multiple choice question has been scrambled)
  147. Redefining one of the JApplet methods is also known as;

    A. overriding.
    B. initializing
    C. hiding
    D. overloading
    A. overriding.
    (this multiple choice question has been scrambled)
  148. In a class containing methods with the same name, the methods are distinguished by:

    A. Return type.
    B. A and B.
    C. B and C.
    D. Number of arguments.
    E. Types of arguments.
    B. A and B.
    (this multiple choice question has been scrambled)
  149. A Java class can have which of the following methods?

    A. foo( double a, double b )
    B. foo( int b )
    C. foo( double a )
    D. foo( int a, int b ) 
    E. foo( int a )
    a. All of the above.
    b. A, B, D, E.
    c. A, B, C, D.
    d. A, C, D, E.
    C. A, B, C, D.
    (this multiple choice question has been scrambled)
  150. An overloaded method is one that;

    A. has a different name as another method, but the same arguments.
    B. has the same name and arguments as a method defined in another class.
    C. has the same name as another method, but different arguments.
    D. has the same name and arguments, but a different return type as another method.
    C. has the same name as another method, but different arguments.
    (this multiple choice question has been scrambled)
  151. A recursive method; 

    a. calls itself directly or indirectly.
    b. has a base case
    c. has a recursive call (or recursion step)
    d. All of the above.
    d. All of the above.
  152. The Java primitive type that holds numbers with the largest absolute value is:

    A. double.
    B. long.
    C. int.
    D. float.
    A. double.
    (this multiple choice question has been scrambled)
  153. Which of the following statements about recursion are true;

    a. Recursion uses repetition by having a method call itself.
    b. Recursion uses a termination test.
    c. Recursion can occur infinitely.
    d. All of the above.
    e. None of the above.
    d. All of the above.
  154. The recursion step should;

    A. make two calls to the recursive method.
    B. call a fresh copy of the recursive method to work on a smaller problem.
    C. check for the base case.
    D. iterate until it reaches a termination condition.
    B. call a fresh copy of the recursive method to work on a smaller problem.
    (this multiple choice question has been scrambled)
  155. The number of calls to the fibonacci method to calculate fibonacci(7) is:

    A. 7
    B. 41
    C. 39
    D. 13
    B. 41
    (this multiple choice question has been scrambled)
  156. Operands in Java are evaluated;

    A. at the same time.
    B. determined at runtime.
    C. right to left.
    D. left to right.
    D. left to right.
    (this multiple choice question has been scrambled)
  157. Recursion is often less efficient than iteration because;

    A. it is not as intuitive.
    B. it can cause an explosion of method calls.
    C. recursive methods are harder to debug.
    D. recursive methods take longer to program.
    B. it can cause an explosion of method calls.
    (this multiple choice question has been scrambled)
  158. All of the following are true for both recursion and iteration except;

    A. they are based on a control statement.
    B. they have a base case.
    C. they can cause infinite loops.
    D. both gradually approach termination.
    B. they have a base case.
    (this multiple choice question has been scrambled)
  159. Recursion often is preferable over iteration because;

    A. it requires less memory.
    B. it is faster.
    C. it models the program more logically.
    d. all of the above.
    C. it models the program more logically.
    (this multiple choice question has been scrambled)
  160. Which of the following statements about arrays are true?

    A. Arrays are a group of variables containing values that all have the same type.
    B. Elements are located by index or subscript.
    C. The seventh element of array c is specified by c[7].
    D. The length of array c is determined by the expression c.length();
    a. A, C, D.
    b. A, B.
    c. C, D.
    d. A, B, C, D.
    B. A, B.

    Statements C and D are false. The length of array c is determined by c.length, and the seventh element of array c is specified by c[6] because index start at 0.
    (this multiple choice question has been scrambled)
  161. Object-Oriented Programming encapsulates:

    A.Classes.
    B.Data and methods.
    C.Information hiding.
    D.Adjectives
    B.Data and methods.
    (this multiple choice question has been scrambled)
  162. If class A extends B, then:

    A. Class A is the superclass.
    B. Class A inherits from class B.
    C. Class B is the derived class.
    D. Class A is the base class.
    B. Class A inherits from class B.  

    Class B is the base class or superclass. Class A is the derived class or subclass.
    (this multiple choice question has been scrambled)
  163. Constructors:

    a. Have the same name as the class.
    b. May not specify a return type.
    c. Initialize objects of a class.
    d. All of the above.
    d. All of the above.
  164. An instance variable is hidden in the scope of a method when;

    A. The instance variable has the same name as the method.
    B. The instance variable has the same name as a local variable in the method.
    C. The instance variable has the same name as the class.
    D. The instance variable has the same name as the file.
    B. The instance variable has the same name as a local variable in the method.
    (this multiple choice question has been scrambled)
  165. Which of the following statements is true?

    A. Within a class’s scope, class members are accessible to all of that class’s methods, but cannot be referenced directly by name.
    B. It is a syntax error if a method declares a local variable with the same name as a variable declared in the method’s enclosing class.
    C. Variables declared in a method are known only to that method.
    d. None of the above.
    C. Variables declared in a method are known only to that method.
    (this multiple choice question has been scrambled)
  166. Which of the following should usually be private?

    A. Methods.
    B. Variables (or fields).
    C. Constructors.
    d. All of the above.
    B. Variables (or fields).
    (this multiple choice question has been scrambled)
  167. Which of the following statements is true?

    A. Information hiding is achieved by restricting access to class members via keyword public.
    B. Methods and instance variables can both be either public or private.
    C. The private members of a class are directly accessible to the client of a class.
    d. None of the above is true.
    B. Methods and instance variables can both be either public or private.
    (this multiple choice question has been scrambled)
  168. When should a program explicitly use the this reference:

    A. Accessing a private variable.
    B. Accessing a field that is shadowed by a local variable.
    C. Accessing a local variable.
    D. Accessing a public variable.
    B. Accessing a field that is shadowed by a local variable.
    (this multiple choice question has been scrambled)
  169. Having a this reference allows:

    a. A method refer explicitly to the instance variables and other methods of the object on which the method was called.
    b. A method to refer implicitly to the instance variables and other methods of the object on which the method was called.
    c. An object to reference itself.
    d. All of the above.
    d. All of the above.
  170. A constructor cannot:

    A. Initialize variables to their defaults.
    B. Have the same name as the class.
    C. Be overloaded.
    D. Specify return types or return values.
    D. Specify return types or return values.
    (this multiple choice question has been scrambled)
  171. Which of the following will be used to create an instance of a class if the programmer does not define a constructor?

    A. A default constructor.
    B. An overloaded constructor.
    C. The Object class constructor with the name of the desired class passed in as an argument.
    D. If no constructor is written, then one isn’t needed.
    A. A default constructor.
    (this multiple choice question has been scrambled)
  172. Constructors:

    A. Initialize instance variables.
    B. a and c.
    C. When overloaded, are selected by number and types of parameters.
    D. When overloaded, can have identical argument lists.
    B. a and c.
    (this multiple choice question has been scrambled)
  173. A well-designed group of constructors:

    a. Guarantee the object is created in a consistent state.
    b. May call common methods.
    c. Allows the class's user flexibility in specifying some or all of the initial instance variable values.
    d. All of the above.
    d. All of the above.
  174. Not using set and get methods is:

    A. A logic error.
    B. A syntax error.
    C. Not good program design.
    d. None of the above.
    C. Not good program design.
    (this multiple choice question has been scrambled)
  175. Using public set methods provides data integrity if:

    A. The instance variables are public.
    B. The programmer provides validity checking.
    C. The instance variables are private.
    D. Both b and c.
    D. Both b and c.
    (this multiple choice question has been scrambled)
  176. Composition:

    a. Is a form of software reuse.
    b. Is using an object reference as a class member.
    c. Is a good design practice.
    d. All of the above.
    d. All of the above.
  177. Which of the following is not true?

    A. Finalizer methods typically return resources to the system.
    B. Memory leaks using Java are rare because of garbage collection.
    C. Objects are marked for garbage collection by the finalizer.
    D. The garbage collector reclaims unused memory.
    C. Objects are marked for garbage collection by the finalizer.

    Objects are marked for garbage collection when there are no more references to the object.
    (this multiple choice question has been scrambled)
  178. Static class variables:

    A. Are final.
    B. Are private.
    C. Are public.
    D. Are shared by all objects of a class.
    D. Are shared by all objects of a class.
    (this multiple choice question has been scrambled)
  179. Which of the following is not true?

    A. A static method can call instance methods directly.
    B. A static method has no this reference.
    C. A static method can be accessed even when no objects of its class have been instantiated.
    D. A static method must be used to access private static instance variables.
    A. A static method can call instance methods directly.
    (this multiple choice question has been scrambled)
  180. Instance variables declared final do not or cannot:

    A. Be modified.
    B. Be initialized.
    C. Cause syntax errors if used as a left-hand value.
    D. Use the principle of least privilege.
    A. Be modified.
    (this multiple choice question has been scrambled)
  181. A package is:

    a. A directory structure used to organize classes and interfaces. 
    b. A mechanism for software reuse.
    c. A group of related classes and interfaces.
    d. All of the above.
    d. All of the above.
  182. A class within a package must be declared public if;

    A. It is in the same directory as the other classes in the package.
    B. It will only be used by other classes in the same package.
    C. It will be used by classes that are not in the same package.
    D. It has a unique name.
    C. It will be used by classes that are not in the same package.

    Classes outside the package cannot use a
    class if the class is not declared public.
    (this multiple choice question has been scrambled)
  183. Consider the statement

    package com.deitel.jhtp5.ch08;

    A. The statement declares a package that exists at deitel.com.
    B. The statement uses the Sun Microsystems convention of package naming.
    C. The statement will generate a compile time error.
    D. The statement specifies a package that can be imported using: import com.deitel.ch08.
    B. The statement uses the Sun Microsystems convention of package naming.
    (this multiple choice question has been scrambled)
  184. When no member access modifier is specified for a method or variable, the method or variable:

    A. Is static.
    B. Is public.
    C. Is private.
    D. Has package access.
    D. Has package access.
    (this multiple choice question has been scrambled)
  185. Java programmers do not focus on:

    A. Carefully documenting classes they design.
    B. Carefully testing classes they design.
    C. Crafting new classes and reusing existing classes.
    D. Understanding class library implementations
    D. Understanding class library implementations

    Information hiding and well-defined interfaces free Java programmers from needing to understand existing class library implementations.
    (this multiple choice question has been scrambled)
  186. Which of the following does not contribute to improved software reusability?

    A. Cataloging schemes and browsing mechanisms.
    B. Licensing schemes and protection mechanisms.
    C. Descriptions of classes that allow programmers to determine whether a class fits their needs.
    D. Quickly creating new class libraries without testing them thoroughly.
    D. Quickly creating new class libraries without testing them thoroughly.
    (this multiple choice question has been scrambled)
  187. Abstract Data Types:

    a. Elevate the importance of data.
    b. Are only approximation or models of real-world concepts and behaviors.
    c. Capture tow notions, data representation and operations.
    d. All of the above.
    d. All of the above.
  188. The term information hiding refers to:

    A. Hiding implementation details from clients of a class.
    B. public methods.
    C. The process of releasing an object for garbage collection.
    D. Accessing static class members. 
    A. Hiding implementation details from clients of a class.
    (this multiple choice question has been scrambled)
  189. Information is passed to a method in:

    A. the method name.
    B. the called method.
    C. the arguments to the method.
    D. that method's return.
    C. the arguments to the method.
    (this multiple choice question has been scrambled)
  190. Counter-controlled repetition requires;

    a. A control variable and initial value.
    b. A control variable increment (or decrement).
    c. A condition that tests for the final value of the control variable.
    d. All of the above.
    d. All of the above.
  191. The control variable of a counter-controlled loop should be declared as:

    A. int.
    B. float.
    C. double.
    d. Any of the above.
    A. int.
    (this multiple choice question has been scrambled)
  192. Consider the following two Java code segments:

    Segment 1

    int i = 0;
    while ( i < 20 ) {
               i++;
               System.out.println( i );
           }

    Segment 2

    for ( int i = 0; i <= 20; i++ ) {
                System.out.println( i );
               } 

    Which of the following statements are true?
    A. Both (a) and (b) are true.
    B. The output from these segments is not the same.
    C. Neither (a) nor (b) is true.
    D. The scope of the control variable i is different for the two segments.
    A. Both (a) and (b) are true.
    (this multiple choice question has been scrambled)
  193. Consider the classes below:

    public class TestA {
           public static void main( String args[] )
                     {
                  int x = 2, y = 20, counter = 0;
        for ( int j = y % x; j < 100; j += ( y / x ) )  
          { counter++;}
       }
    }

    public class TestB {
    public static void main(String args[])
    {
           int counter = 0;
           for ( int j = 10; j > 0; --j ) {
                   ++counter;
          }}
     }

    Which of the following statements is true?

    A. The value of j will be the same for each loop for all iterations
    B. Both (a) and (b) are true.
    C. Neither (a) nor (b) is true.
    D. The value of counter will be the different at the end of each for loop for each class.
    C. Neither (a) nor (b) is true.
    (this multiple choice question has been scrambled)
  194. Which of the following for-loop control headers results in equivalent numbers of iterations:

    A.  for ( int q = 99; q > 0; q -= 9 )
    B.  for ( int q = 100; q >= 0; q-- )
    C.  for ( int q = 1; q <= 100; q++ )
    D.  for ( int q = 990; q > 0; q -= 90 )

    a. A and B.
    b. C and D.
    c. A and B have equivalent iterations and C and D have equivalent iterations.
    d. None of the loops have equivalent iterations.
    B. C and D.
    (this multiple choice question has been scrambled)
  195. Which of the following will count down from 10 to 1 correctly?

    A. for ( int j = 1; j <= 10; j++ )
    B. for ( int j = 10; j <= 1; j++ )
    C. for ( int j = 10; j > 1; j-- )
    D. for ( int j = 10; j >= 1; j-- )
    D. for ( int j = 10; j >= 1; j-- )
    (this multiple choice question has been scrambled)
  196. Which of the following statements about a do...while repetition statement is true?

    A. The body of a do...while loop is executed only once.
    B. The body of a do...while loop is always executed at least once.
    C. The body of a do...while loop is executed only if the terminating condition is true.
    d. None of the above
    B. The body of a do...while loop is always executed at least once.
    (this multiple choice question has been scrambled)
  197. Which of the following will not help prevent infinite loops?

    A. If the loop is sentinel-controlled, ensure that the sentinel value is input eventually.
    B. Ensure that the header of a for or while statement is not followed by a semicolon.
    C. Include braces around the statements in a do...while statement.
    D. If the loop is counter-controlled, the body of the loop should increment or decrement the counter as needed.
    C. Include braces around the statements in a do...while statement.
    (this multiple choice question has been scrambled)
  198. For the two code segments below:

    Segment A

    int q = 5;
    switch( q ) {
             case 1: System.out.println( 1 );
             case 2: System.out.println( 2 );
             case 3: System.out.println( 3 );
             case 4: System.out.println( 4 );
             case 5: System.out.println( 5 );
          default: System.out.println( "default" );
      } 

    Segment B

    q = 4;
    switch( q ) {
             case 1: System.out.println( 1 );
             case 2: System.out.println( 2 );
             case 3: System.out.println( 3 );
             case 4: System.out.println( 4 );
             case 5: System.out.println( 5 );
          default: System.out.println( "default" );
      } 

    Which of the following statements is true?

    b. The output for Segment A is:
           default
    c. The output for Segment B is:
            4
    d. The output for Segment B is:
            45default
    e. The output for Segment A is:
                 5
                 default
    • e. The output for Segment A is:           
    •           5             
    •           default
  199. For the code segment below,

    switch( q ) {
         case 1: System.out.println( "apple" );
      break;
         case 2: System.out.println( "orange" );
      break;
         case 3: System.out.println( "banana" );
      break;
         case 4: System.out.println( "pear" );
         case 5: System.out.println( "grapes" );
      default: System.out.println( "kiwi" );


    Which of the following values for q will result in kiwi being output?

    A. 3.
    B. 2.
    C. 4 and anything greater than 4.
    D. 1.
    C. 4 and anything greater than 4.
    (this multiple choice question has been scrambled)
  200. Which of the following statements about break and continue statements is true?

    A. The continue statement is used to exit a repetition structure early and continue execution after the loop.
    B. The break statement, when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
    C. The continue statement, when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
    D. The continue statement is used to continue after a switch statement.
    C. The continue statement, when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
    (this multiple choice question has been scrambled)
  201. To exit out of a loop completely, and resume the flow of control at the next line in the method, use _______.

    A. A continue statement.
    B. A return statement.
    C. A break statement.
    d. Any of the above.
    C. A break statement.
    (this multiple choice question has been scrambled)
  202. Which of the following statements is not true?

    A. A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement.
    B. A break statement can only break out of an immediately enclosing while, for, do...while or switch statement.
    C. Labeled continue statements break out of any number of enclosing repetition structures, and continue execution with next iteration of the labeled repetition structure.
    D. Labeled break statements break out of any number of enclosing repetition structures.
    a. A and C.
    b. B and D.
    c. None of the above are true.
    d. All of the above are true.
    C. All of the above are true.
    (this multiple choice question has been scrambled)
  203. Labeled break statements cannot be used to break out of which of the following?

    A. A method.
    B. A switch statement.
    C. A for loop.
    D. A while statement.
    A. A method.
    (this multiple choice question has been scrambled)
  204. Consider the code segment below.

         if ( gender == 1 )
            if ( age >= 65 )
             ++seniorFemales;

    This segment is equivalent to which of the following?

    a. if ( gender == 1 || age >= 65)      
               ++seniorFemales;
    b. if ( gender == 1 && age >= 65 )
               ++seniorFemales;
    c. if ( gender == 1 AND age >= 65 )
               ++seniorFemales;
    d. if ( gender == 1 OR age >= 65 )
               ++seniorFemales;
    b. if ( gender == 1 && age >= 65 )            ++seniorFemales;
  205. Which case of the following would warrant using the boolean logical inclusive OR (|) rather than the conditional OR (||)?

    A. Testing if at least one of two conditions is true when the left operand has a required side effect.
    B. Testing if at least one of two conditions is true when the right operand has a required side effect.
    C. Testing if two conditions are both true.
    D. Testing if at least one of two conditions is true.
    B. Testing if at least one of two conditions is true when the right operand has a required side effect.
    (this multiple choice question has been scrambled)
  206. Which statement below is not true?

    A. Structured programming promotes simplicity.
    B. Structured programming produces programs are easier to test.
    C. Structured programming requires four forms of control.
    D. Structured programming produces programs that are easier to modify
    C. Structured programming requires four forms of control.

    (Only three forms are necessary: sequence,
    selection, repetition)
    (this multiple choice question has been scrambled)
  207. Which of the following is NOT a way that repetition is implemented in Java programs?

    A. if structures.
    B. while structures.
    C. for structures.
    D. do...while structures.
    A. if structures.
    (this multiple choice question has been scrambled)
  208. Which of the following statements is not true?

    A. A superclass object is a subclass object.
    B. Java uses interfaces to provide the benefits of multiple inheritance.
    C. The class following the extends keyword in a class declaration is the direct superclass of the class being declared.
    D. A subclass is generally larger than its superclass.
    A. A superclass object is a subclass object.
    (this multiple choice question has been scrambled)
  209. Which term applies to the largest class in a class hierarchy?

    A. Subclass.
    B. Superclass.
    C. Base class.
    D. Parent class.
    B. Superclass.
    (this multiple choice question has been scrambled)
  210. Focusing on the commonalities among objects in a system rather than specifics is known as;

    A. Simplification.
    B. Inheritance.
    C. Abstraction.
    D. Encapsulation.
    C. Abstraction.
    (this multiple choice question has been scrambled)
  211. Inheritance is also known as the;

    A. “uses-a” relationship.
    B. “has-a” relationship.
    C. “knows-a” relationship.
    D. “is-a” relationship.
    D. “is-a” relationship.
    (this multiple choice question has been scrambled)
  212. Which of the following is not a superclass/subclass relationship?

    A. Ford/Taurus.
    B. Sailboat/Tugboat.
    C. Country/USA.
    D. University/Brown University.
    B. Sailboat/Tugboat.

    A Sailboat is not a superclass for Tugboats. Both sailboat and tugboats would be subclasses of Boat.
    (this multiple choice question has been scrambled)
  213. An advantage of inheritance is that:

    A. Objects of a subclass can be treated like objects of their superclass.
    B. All methods can be inherited.
    C. All instance variables can be uniformly accessed by subclasses and superclasses.
    d. None of the above.
    A. Objects of a subclass can be treated like objects of their superclass.

    Note: constructors cannot be inherited,
    and instance variables that are private in a superclass cannot be directly accessed by a subclass.
    (this multiple choice question has been scrambled)
  214. Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

    A. protected.
    B. public.
    C. super.
    D. this.
    C. super.
    (this multiple choice question has been scrambled)
  215. Using the protected keyword gives a member:

    A. public access.
    B. private access.
    C. package access.
    D. block scope.
    C. package access.
    (this multiple choice question has been scrambled)
  216. Superclass methods with this level of access cannot be called from subclasses;

    A. package.
    B. protected.
    C. public.
    D. private.
    D. private.
    (this multiple choice question has been scrambled)
  217. Overriding a method differs from overloading a method because;

    A. Overridden methods have the same signature.
    B. For an overloaded constructor, the superclass constructor will always be called first.
    C. For an overridden constructor, the superclass constructor will always be called first.
    D. Overloaded methods have the same signature.
    A. Overridden methods have the same signature.
    (this multiple choice question has been scrambled)
  218. Consider the classes below, declared in the same file:

          class A {
                        int a;
                        public A() {
                            a = 7;
                          }
                      }

          class B extends A {
                        int b;
                        public B() {
                            b = 8;
                                      }
                                 }

    Which of the statements below is not true?

    A. After the constructor for class B is executed, the variable a will have the value 7.
    B. A reference to class A can be treated as a reference to class B.
    C. After the constructor for class B is executed, the variable b will have the value 8.
    D. Both variables a and b are instance variables.
    B. A reference to class A can be treated as a reference to class B. 

    The converse is true because class A is the superclass. Note that variables a and b both have package access.
    (this multiple choice question has been scrambled)
  219. Accessing a superclass method through a subclass reference is;

    A. Inheritance.
    B. Straightforward.
    C. A syntax error.
    D. Polymorphism.
    C. A syntax error.
    (this multiple choice question has been scrambled)
  220. Private fields of a superclass can be accessed in a subclass;

    A. by calling public or protected methods declared in the superclass.
    B. directly.
    C. by calling private methods declared in the superclass.
    d. All of the above.
    A. by calling public or protected methods declared in the superclass.
    (this multiple choice question has been scrambled)
  221. Which statement below is not true?

    A. Finalizers and constructors should always be declared protected so subclasses have access to the method.
    B. Superclass constructors should always be called as the first statement of a subclass constructor.
    C. All are not true.
    D. Superclass finalizers should always be called as the last statement of a subclass finalizer.
    A. Finalizers and constructors should always be declared protected so subclasses have access to the method.

    Constructors should be declared public so classes that use their classes can instantiate them.
    (this multiple choice question has been scrambled)
  222. Finalizers are used to:

    A. Initialize variables.
    B. Draw the applet or JFrame used by an application.
    C. Clean up an object of a class before it is garbage collected.
    D. Ensure than all variables are assigned valid values.
    C. Clean up an object of a class before it is garbage collected.
    (this multiple choice question has been scrambled)
  223. Which of the following sequences is in the correct order?

    A. Subclass constructor, superclass constructor, superclass finalizer, subclass finalizer.
    B. Superclass constructor, subclass constructor, subclass finalizer, superclass finalizer.
    C. Superclass constructor, subclass constructor, superclass finalizer, subclass finalizer.
    D. Subclass constructor, superclass constructor, subclass finalizer, superclass finalizer.
    B. Superclass constructor, subclass constructor, subclass finalizer, superclass finalizer.
    (this multiple choice question has been scrambled)
  224. Which of the following statements are true?

    A. A superclass can be modified without modifying subclasses
    B. A superclass specifies commonality.
    C. A subclass can be modified without modifying its superclass.
    D. We can use inheritance to customize existing software.
    a. All of the above.
    b. None of the above.
    c. A, B and C.
    d. A, B and D.
    D. All of the above.
    (this multiple choice question has been scrambled)
  225. Which of the following is an example of a functionality that should not be “factored out” to a superclass?

    A. All vehicles know how to start and stop.
    B. All animals lay eggs, except for mammals.
    C. Both ducks and geese are birds that know how to start flying from the water.
    D. All paints have a color.
    B. All animals lay eggs, except for mammals.
    (this multiple choice question has been scrambled)
  226. Polymorphism enables the programmer to;

    A. hide information from the user.
    B. absorb attributes and behavior from previous classes.
    C. program in the general.
    D. program in the specific.
    C. program in the general.
    (this multiple choice question has been scrambled)
  227. Classes declared completely inside other classes are called;

    A. superclasses.
    B. subclasses.
    C. nested classes.
    D. abstract classes.
    C. nested classes.
    (this multiple choice question has been scrambled)
  228. Which statement best describes the relationship between superclass and subclass types?

    A. A subclass reference cannot be assigned to a superclass variable and a superclass reference cannot be assigned to a subclass variable.
    B. A superclass reference can be assigned to a subclass variable, but a subclass reference cannot be assigned to a superclass variable.
    C. A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
    D. A subclass reference can be assigned to a superclass variable and a superclass reference can be assigned to a subclass variable.
    C. A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
    (this multiple choice question has been scrambled)
  229. For which of the following would polymorphism not provide a clean solution?

    A. A program to compute savings account interest.
    B. A billing program where there is a variety of clients who are billed with different fee structures.
    C. A maintenance log program where a variety of machine data is collected and maintenance schedules are produced for each machine based on the data collected.
    D. An IRS program that maintains information on a variety of taxpayers and determines who to audit based on

    criteria for classes of taxpayers
    A. A program to compute savings account interest.

    Since there is only one kind of calculation, there is no need for polymorphism.
    (this multiple choice question has been scrambled)
  230. Polymorphism allows for specifics to be dealt with during;

    A. debugging.
    B. execution time.
    C. programming.
    D. compile time.
    B. execution time.
    (this multiple choice question has been scrambled)
  231. A(n) _______ class cannot be instantiated.

    A. concrete.
    B. final.
    C. static.
    D. abstract.
    D. abstract.
    (this multiple choice question has been scrambled)
  232. Non-abstract classes are called;

    A. instantiable classes.
    B. concrete classes.
    C. instance classes.
    D. real classes.
    B. concrete classes.
    (this multiple choice question has been scrambled)
  233. Declaring a non-abstract class with an abstract method is;

    A. a logic error.
    B. allowable if the class is static.
    C. a syntax error.
    d. none of the above.
    C. a syntax error.
    (this multiple choice question has been scrambled)
  234. If the superclass contains only abstract method declarations, the superclass is used for:

    A. Implementation inheritance.
    B. Neither a nor b.
    C. Both a and b.
    D. Interface inheritance.
    D. Interface inheritance.
    (this multiple choice question has been scrambled)
  235. Which of the following statements about abstract superclasses is true?

    A. abstract superclasses may not contain implementations of methods.
    B. abstract superclasses must declare all data members not given values as abstract.
    C. abstract superclasses must declare all methods as abstract.
    D. abstract superclasses may contain data.
    D. abstract superclasses may contain data.
    (this multiple choice question has been scrambled)
  236. Classes and methods are declared final for all but the following reasons:

    A. final methods and classes prevent further inheritance.
    B. final methods allow inlining the code.
    C. final methods can improve performance.
    D. final methods are static.
    D. final methods are static.
    (this multiple choice question has been scrambled)
  237. All of the following methods are implicitly final except;

    A. a static method.
    B. a private method.
    C. a method in an abstract class.
    D. a method declared in a final class.
    C. a method in an abstract class.
    (this multiple choice question has been scrambled)
  238. Declaring a method final means;

    A. it will prepare the object for garbage collection.
    B. it cannot be overridden.
    C. it cannot be accessed from outside its class.
    D. it cannot be overloaded.
    B. it cannot be overridden.
    (this multiple choice question has been scrambled)
  239. Consider the abstract superclass below:
         public abstract class Foo {
                                 private int a;
                                 public int b;
                  public Foo( int aVal, int bVal )
                                {
                                     a = aVal;
                                     b = bVal;
                                 }
               public abstract int calculate();
          }

    Any concrete subclass that extends class Foo;

    a. Must implement a method called calculate().
    b. Will not be able to access the instance variable a.
    c. Will not be able to instantiate an object of class Foo.
    d. All of the above.
    d. All of the above.
  240. Consider the superclass below:

          public class Foo {
                         private int a;
                         public int b;
                public Foo( int aVal, int bVal )
                                   {
                                    a = aVal;
                                    b = bVal;
                                     }
               public int calculate()
                      {
                        return a + b;
                      }
              }

    A subclass that extends class Foo;

    a. Must override the method calculate().
    b. Will not be able to access the instance variable a.
    c. Will not be able to instantiate an object of class Foo.
    d. All of the above.
    b. Will not be able to access the instance variable a.
  241. Which of the following does not complete the sentence correctly?
    An interface ____________ .

    A. Is used in place of an abstract class when there is no default implementation to inherit.
    B. Can be instantiated.
    C. Is declared in a file by itself saved to the same name as the interface and the .java extension.
    D. Forces classes that implement it to declare all the interface methods.
    B. Can be instantiated.
    (this multiple choice question has been scrambled)
  242. To indicate that a reference always refers to the same object, use the keyword ________.

    A. interface.
    B. abstract.
    C. static. 
    D. final.
    D. final.
    (this multiple choice question has been scrambled)
  243. An interface may contain;

    A. private static data and public final methods.
    B. public static final data and public abstract methods.
    C. only public abstract methods.
    D. private static data and public abstract methods.
    B. public static final data and public abstract methods.
    (this multiple choice question has been scrambled)
  244. A class that implements an interface but does not declare all of the interface’s methods must be declared;

    A. final
    B. interface
    C. abstract
    D. public
    C. abstract
    (this multiple choice question has been scrambled)
  245. Which of the following answers does not complete the sentence correctly?
    An inner class ____________ .

    A. Is frequently used for GUI event handling.
    B. Can access method variables from the method in which it was declared.
    C. Does not need a handle to its outer class for methods and variables.
    D. May be anonymous.
    B. Can access method variables from the method in which it was declared. 

    The inner class can only access final variables from the method.
    (this multiple choice question has been scrambled)
  246. Consider the code segment below:

      public class TestClassA {
              private int var1;
              public int var2;
              private TestClassB tcB;

              public TestClassA()
                {
                    var1 = 9;
                    var2 = 11;
                    tcB = new TestClassB();

                 }

               public String toString()
                 {
                     return "testclassA: " + var1 + " " + var2 + " " + tcB;
                  }

           public static void main( String args[] )
                 {
                 TestClassA ai = new TestClassA();
                 System.out.println( ai );
                 }

             private class TestClassB {
                   private int var3;
                   public int var4;

             public TestClassB ()
                {
                   var3 = var1 + var2;
                   var4 = var2 - var1;
                 }

             public String toString()
                {
                    return "testclassb: " + var3 + " " + var4;
                }
         }
    }

    The output from this segment will be;

    A. None, accessing var1 in TestClassB will cause a syntax error.
    B. None, accessing var2 in TestClassB will cause a syntax error.
    C. testclassA: 9 11 testclassb: 20 2.
    D. testclassb: 20 2 testclassA: 9 11.
    C. testclassA: 9 11 testclassb: 20 2.
    (this multiple choice question has been scrambled)
  247. Which of the following statements is true?

    A. Each nested class will have its own .class file.
    B. All nested classes can be declared public, protected, package access or private.
    C. Each nested class is associated with the instantiation of one outer class and can only be accessed once instantiated.
    D. None of these statements are true.
    A. Each nested class will have its own .class file.
    (this multiple choice question has been scrambled)
  248. An inner class;

    A. is non-static.
    B. is the same as a nested class.
    C. is a top-level class.
    D. is defined in its own file.
    A. is non-static.
    (this multiple choice question has been scrambled)
  249. Type wrapper classes;

    a. Enable you to manipulate primitives as objects.
    b. Enable you to manipulate primitives polymorphically.
    c. Exist for all primitive types.
    d. All of the above.
    d. All of the above.
  250. Which of the following is not a type-wrapper class?

    A. Boolean.
    B. String.
    C. Character.
    D. Short.
    B. String.
    (this multiple choice question has been scrambled)
  251. The numeric type-wrapper classes extend which class?

    A. Number.
    B. String.
    C. Object.
    D. Byte.
    A. Number.
    (this multiple choice question has been scrambled)
  252. In the Java coordinate system, the point (0,0) is;

    A. The upper-left corner of the screen.
    B. The lower-right corner of the screen.
    C. The upper-right corner of the screen.
    D. The lower-left corner of the screen.
    A. The upper-left corner of the screen.
    (this multiple choice question has been scrambled)
  253. Which of the following statements about the Graphics object is true?

    A. The Graphics class is abstract.
    B. The Graphics object is an argument to the applet's update method.
    C. The Graphics object manages a graphics context.
    D. The Graphics object is instantiated by the user.
    E. The Graphics object is the argument to the applet's paint method.
    a. A, C, E.
    b. A, C, D, E.
    c. A, B, D, E.
    d. All are true.
    D. A, C, D, E.
    (this multiple choice question has been scrambled)
  254. The Component method repaint causes;

    A. Component method paint to be called followed by calling Component method update.
    B. Component method update to be called followed by calling Component method paint.
    C. Component method update to be called only.
    D. Component method paint to be called only.
    B. Component method update to be called followed by calling Component method paint.
    (this multiple choice question has been scrambled)
  255. Which of the following are valid Java statements, or groups of statements?

    A. Color c = new Color( 0.0f, 1.0f, 0.0f );
    B. setGreen( c.getGreen() – 2 );
    C. Color c = new Color( 0, 255, 0 );
    D. Color c = new Color( 0.0d, 1.0d, 0.0d );
    E. Color c = new Color( 0, 255, 0 );
    a. All of the above.
    b. A, B, C.
    c. A, B, D.
    d. A, B.
    E. A, B.
    (this multiple choice question has been scrambled)
  256. The JColorChooser dialog allows colors to be chosen by all but which of the following?

    A. Red, Green, Blue.
    B. Gradient, cycle, brightness.
    C. Swatches.
    D. Hue, saturation, brightness.
    B. Gradient, cycle, brightness.
    (this multiple choice question has been scrambled)
  257. Which of the following are valid Font constructors?

    A. Font f = new Font( 20, Font.Bold, "Monospaced" );
    B. Font f = new Font( Font.Bold, 20, "SansSerif" ); 
    C. Font f = new Font();
    D. Font f = new Font( "Serif", Font.Bold + Font.Italic, 19 );

    a. A and B.
    b. B and C.
    c. B.
    d. D.
    B. B.
    (this multiple choice question has been scrambled)
  258. Which of the following is correct for font metrics?

    a. height = descent + ascent + leading.
    b. The amount the character dips below the baseline is the ascent.
    c. The amount the character can be above the baseline is the leading.
    d. The amount the character rises above the baseline is the descent.
    a. height = descent + ascent + leading.
  259. The Java statement:

    g.fillOval( 290,100,90,55 );

    A. Draws a filled oval with its center at coordinates x=290, y=100, with height=90 and width=55.
    B. Draws a filled oval with its left most point at coordinates x=290, y=100, with height=90 and width=55.
    C. Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with height 90=and width=55.
    D. Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with height=55 and width=90.
    D. Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with height=55 and width=90.
    (this multiple choice question has been scrambled)
  260. The Java statement;

    g.draw3DRect( 290,100,90,55,true );

    A. draws a rectangle that is lowered (the top and left edges of the rectangle are slightly darker than the rectangle).
    B. draws a rectangle that is raised (the top and left edges of the rectangle are slightly darker than the rectangle).
    C. draws a rectangle that is lowered (the bottom and right edges of the rectangle are slightly darker than the rectangle).
    D. draws a rectangle that is raised (the bottom and right edges of the rectangle are slightly darker than the rectangle).
    D. draws a rectangle that is raised (the bottom and right edges of the rectangle are slightly darker than the rectangle).
    (this multiple choice question has been scrambled)
  261. Which of the following statements about arcs is not true?

    A. Arcs sweep from a starting angle the number of degrees specified by their arc angle.
    B. Arcs that sweep clockwise are measured in positive degrees.
    C. An arc is drawn as a part of an oval.
    d. None of the above statements are false.
    B. Arcs that sweep clockwise are measured in positive degrees.
    (this multiple choice question has been scrambled)
  262. Which of the following statement draws an arc that sweeps from the top of an oval to the left-most edge?
    The oval is twice as wide as high.

    A. g.drawArc( 100, 200, 50, 100, 90, 180 );
    B. g.drawArc( 100, 200, 50, 100, 180. 90 );
    C. g.drawArc( 200, 100, 100, 50, 180, 90 );
    D. g.drawArc( 200, 100, 100, 50, 90, 90 );
    D. g.drawArc( 200, 100, 100, 50, 90, 90 );
    (this multiple choice question has been scrambled)
  263. Consider the code segment below:

    int xValues[] = { 100, 150, 200, 100 };
    int yValues[] = { 30, 130, 30, 30 };
    g.drawPolyline( xValues, yValues, 4 );

    This code segment will draw;

    A. A triangle with a corner at its upper most position and an edge at its lowest position.
    B. A triangle with an edge at its upper most position and a corner at its lowest position.
    C. A V with its corner at the bottom.
    D. A V with its corner at the top.
    B. A triangle with an edge at its upper most position and a corner at its lowest position.
    (this multiple choice question has been scrambled)
  264. Consider the Java code segment below:

           Polygon poly2 = new Polygon();
           poly2.addPoint( 100, 30 );
           poly2.addPoint( 100, 130 );

    Which of the following will create a polygon that is a square?

    a. poly2.addPoint( 200, 30 );
           poly2.addPoint( 200, 130 );
    b. poly2.addPoint( 200, 130 );
           poly2.addPoint( 200, 30 );
    c. poly2.addPoint( 130, 30 );
           poly2.addPoint( 130, 130 );
    d. poly2.addPoint( 130, 130 );
           poly2.addPoint( 130, 30 );
    • b. poly2.addPoint( 200, 130 );              
    •        poly2.addPoint( 200, 30 );
  265. Which of the following statements about the Java2D API is not true?

    a. A Graphics2D object is instantiated to draw Java2D figures.
    b. Class Graphics2D is a subclass of class Graphics.
    c. To access Graphics2D capabilities, downcast the Graphics reference passed to paint to a Graphics2D reference.
    d. All of the above are true.
    d. All of the above are true.
  266. The Graphics2D method(s) that determine(s) the color and texture for the shape to display is/are;

    A. setStroke();
    B. setTexturePaint();
    C. setTexture() and setColor();
    D. setPaint();
    D. setPaint();
    (this multiple choice question has been scrambled)
  267. Which of the following statements is not true?

    A. Class BufferedImage can be used to produce images in color and gray scale.
    B. Class GradientPaint draws a shape in a gradually changing color.
    C. A BufferedImage object uses the image stored in its associated TexturePaint object as the fill texture for a filled-in shape.
    d. All of the above are true.
    C. A BufferedImage object uses the image stored in its associated TexturePaint object as the fill texture for a filled-in shape.
    (this multiple choice question has been scrambled)
  268. __________________________ is a form of software reusability in which new classes acquire the members of existing classes and embellish those classes with new capabilities.
    inheritance
  269. True/False  A has-a relationship is implemented via inheritance.
    False.  

    A "has a" relationship is implemented via composition.
  270. In a(n) _______ relationship, a class object has references to objects of other classes as members.
    has-a
  271. Which of the following is the superclass constructor call syntax?

    A) keyword super followed by a dot(.)
    B) keyword super followed by a set of parentheses containing the superclass constructor arguments
    C) keyword super followed by a dot(.) and the superclass constructor name
    d) None of the above
    B) keyword super followed by a set of parentheses containing the superclass constructor arguments
    (this multiple choice question has been scrambled)
  272. A superclass's ____________ and ___________ members can be accessed in the superclass declaration and in subclass declarations.
    public and protected
  273. Inheritance is sometimes referred to as ___________________.
    specialization
  274. Which statement is true when a superclass has protected instance variables?

    a) A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state.
    b) Subclass methods are more likely to be written so that they depend on the superclass's data implementation. 
    c) We may need to modify all the subclasses of the superclass if the superclass implementation changes.
    d) ALL OF THE ABOVE
    d) ALL OF THE ABOVE are true

    • a) A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state.
    • b) Subclass methods are more likely to be written so that they depend on the superclass's data implementation. 
    • c) We may need to modify all the subclasses of the superclass if the superclass implementation changes.
  275. True/False  Superclass constructors are not inherited by subclasses.
    True
  276. A subclass explicitly inherits from this kind of superclass;
    direct superclass
  277. This access modifier offers an intermediate level of access. Variables declared with this modifier in a superclass can be accessed by members of the superclass, by members of its subclasses, and by members of other classes in the same package;
    protected
  278. In a(n) ______ relationship, an object of a subclass can also be treated as an object of its superclass.
    is-a
  279. Fields labeled private in a superclass can be accessed in a subclass by;
    by calling public or protected methods declared in the superclass.
  280. Superclass methods with this level of access cannot be called from subclasses;
    private
  281. Every class in Java, except ________, extends an existing class.

    A) Class
    B) String
    C) Integer
    D) Object
    D) Object
    (this multiple choice question has been scrambled)
  282. Subclass constructors can call superclass constructors via the keyword _________.
    super
  283. True/False   A Car class has a has-a relationship with the Vehicle class.
    False
  284. Overriding a method differs from overloading a method because:
    Overridden methods have the same signature.
  285. Choose the answer(s) that lists the complete set of statements that are true:

    a) A subclass is more specific than its superclass.
    c) A subclass can access the protected members of its superclass.
    d) A superclass method can be overridden in a subclass.
    e) The first task of any subclass constructor is to call its direct superclass's constructor.
    • a) A subclass is more specific than its superclass.
    • c) A subclass can access the protected members of its superclass.
    • d) A superclass method can be overridden in a subclass.
    • e) The first task of any subclass constructor is to call its direct superclass's constructor.
  286. Which of the following is the superclass constructor call syntax?

    A) keyword super followed by a set of parentheses containing the superclass constructor arguments
    B) keyword super followed by a dot(.) and the superclass constructor name
    C) keyword super followed by a dot(.)
    d) None of the above
    A) keyword super followed by a set of parentheses containing the superclass constructor arguments
    (this multiple choice question has been scrambled)
  287. Inheritance is also known as the;
    "is-a" relationship.
  288. Composition is also known as the;
    "has-a" relationship.
  289. Private fields of a superclass can be accessed in a subclass by;
    by calling public or protected methods declared in the superclass.
  290. In single inheritance, a class exists in a(n) _______________ relationship with its subclasses.
    hierarchical
  291. Which of the keyword allows a subclass to access a superclass method even when the subclass has overridden the superclass method?
    super
  292. Which of the following statements is (are) true?

    a) We can use inheritance to customize existing software.
    b) A superclass specifies commonality.
    c) A superclass can be modified without modifying subclasses
    d) A subclass can be modified without modifying its superclass.
    e) All of the above
    e) All of the above
  293. True/False   When a subclass redefines a superclass method by using the same signature, the subclass is said to overload that superclass method.
    False
  294. Which of the following statements is false?

    A) A superclass object is a subclass object
    B) A subclass is generally larger than it's superclass
    C) The class following the extends keyword in a class declaration is the direct superclass of the class being declared
    D) java uses interfaces to provide the benefits of multiple inheritance
    A) A superclass object is a subclass object
    (this multiple choice question has been scrambled)
  295. An advantage of inheritance is that:
    Objects of a subclass can be treated like objects of their superclass.
  296. Using the protected keyword gives a member:
    package access
  297. Every class in Java, except ________, extends an existing class.
    object
  298. To avoid duplicating code, use ________, rather than ________.
    inheritance, the "copy-and-past" approach.
  299. Consider the classes below, declared in the same file:
             class A {int a;public A() {a = 7;}}
          class B extends A {int b;public B() {b = 8;} }

    Which of the statements below is false?

    A) After the constructor for class B executes, the variable a will have the value 7.
    B) A reference of type A can be treated as a reference of type B.
    C) After the constructor for class B executes, the variable b will have the value 8.
    D) Both variables a and b are instance variables.
    B) A reference of type A can be treated as a reference of type B.
    (this multiple choice question has been scrambled)
  300. Which superclass members are inherited by all subclasses of that superclass?
    protected instance variables and methods.
  301. Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass's method causes ________.
    infinite recursion
  302. When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable?

    A) the program compiles and runs because the instance variables are initialized to their default values.
    B) A syntax error occurs
    C) A run-time errors occurs
    D) A compile-time error occurs
    A) the program compiles and runs because the instance variables are initialized to their default values.
    (this multiple choice question has been scrambled)
  303. Which of the following is an example of a functionality that should not be "factored out" to a superclass?

    A) Both ducks and geese are birds that know how to start flying from the water.
    B) All paints have a color.
    C) All vehicles know how to start and stop.
    D) All animals lay eggs, except for mammals.
    D) All animals lay eggs, except for mammals.
    (this multiple choice question has been scrambled)
  304. The default implementation of method clone of Object performs a ________.

    A) deep copy
    B) full copy
    C) empty copy
    D) shallow copy
    D) shallow copy
    (this multiple choice question has been scrambled)
  305. The default equals implementation determines:

    A) whether two references have the same type.
    B) whether two references refer to the same object in memory.
    C) whether two objects have the same instance variables.
    D) whether two objects have the same instance variable values.
    B) whether two references refer to the same object in memory.
    (this multiple choice question has been scrambled)
  306. Class ________ represents an image that can be displayed on a JLabel.
    ImageIcon
  307. Which method changes the text the label displays?
    setText
  308. Polymorphism enables you to:
    program in the general
  309. If the superclass contains only abstract method declarations, the superclass is used for:
    interface inheritance
  310. Answer by choosing the correct set of true statements:

    A) You make a class abstract by declaring it with keyword abstract.
    B) All statements are true.
    C) The purpose of an abstract class is to provide an appropriate superclass from which other classes can inherit and share the same design.
    D) Abstract classes are used as superclasses in inheritance hierarchies.
    E) Objects cannot be created from an abstract class.
    B) All statements are true.
    (this multiple choice question has been scrambled)
  311. Which of the following does not complete the sentence correctly? An interface;
    can be instantiated.
  312. Classes and methods are declared final for all but the following reasons:
    final methods are static.
  313. Classes from which objects can be instantiated are called __________ classes.
    concrete
  314. Assigning a subclass reference to a superclass variable is safe:

    A) only when the superclass is abstract.
    B) only when the superclass is concrete.
    C) because the subclass object is an object of its superclass.
    D) because the subclass object has an object of its superclass.
    C) because the subclass object is an object of its superclass.
    (this multiple choice question has been scrambled)
  315. If a class contains at least one abstract method, it's a(n) ___________ class.
    abstract
  316. For which of the following would polymorphism not provide a clean solution?
    A program to compute a 5% savings account interest for a variety of clients.
  317. True/False  All methods in an abstract class must be declared as abstract methods.
    False
  318. Which of the following statements about abstract superclasses is true?
    abstract superclasses may contain data.
  319. An interface may contain:
    public static final data and public abstract methods.
  320. True/False  To use an interface, a concrete class must specify that it implements the interface and must declare each method in the interface with the signature specified in the interface declaration.
    True
  321. Which of the following statements about interfaces is false?
    An interface describes a set of methods that can be called on an object, providing a default implementation for the methods.
  322. Which statement best describes the relationship between superclass and subclass types?
    A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
  323. Non-abstract classes are called:
    concrete classes
  324. Consider classes A, B and C, where A is an abstract superclass, B is a concrete class that inherits from A and C is a concrete class that inherits from B. Class A declares abstract method originalMethod, implemented in class B. Which of the following statements is true of class C?
    None of the above.
  325. True/False  Failure to implement a superclass's abstract methods in a subclass is a compilation error unless the subclass is also declared abstract.
    True
  326. Polymorphism allows for specifics to be dealt with during:
    execution
  327. Which keyword is used to specify that a class will define the methods of an interface?
    implements
  328. All of the following methods are implicitly final except:
    a method in an abstract class.
  329. This type of class cannot be a superclass.
    final
  330. It is a UML convention to denote the name of an abstract class in:
    italics
  331. A(n) ___________ class cannot be instantiated.
    abstract
  332. Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?
    public abstract int method1();
  333. When a superclass variable refers to a subclass object and a method is called on that object, the proper implementation is determined at execution time. What is the process of determining the correct method to call?

    A) just in time binding
    B) execution binding
    C) late binding
    D) execution time binding
    C) late binding
    (this multiple choice question has been scrambled)
  334. Every object in Java knows its own class and can access this information through this method;
    getClass
  335. Declaring a method final means:
    it cannot be overridden.
  336. The UML distinguishes an interface from other classes by placing the word "interface" in ________________ above the interface name.
    guillemets
  337. Interfaces can have __________________  methods.
    any number of
  338. Which of the following is not possible?
    A class that inherits from two classes.
  339. A class that implements an interface but does not declare all of the interface's methods must be declared:
    abstract.
  340. Constants declared in an interface are implicitly;
    static
  341. True/False  In a class diagram, properties may be related to the instance variables of a class.
    True
  342. True/False  It is permissable to leave get and set methods for the instance variables of a class out of the class diagram.
    True
  343. Which of the following statements describe the type(s) of relationships that may be described by class diagrams?
    Only static relationships can be defined by class diagrams.
  344. Operations in a class diagram correspond to _____ in Java.
    methods
  345. The proper way to indicate that a class property may have no value entered into it is ____________.
    to use a lower bound of zero.
  346. Which of the following may be represented in a class diagram?
    • Properties of a class.
    • Operations or methods of a class.
    • Constraints on relationships between classes.
  347. The UML syntax for operations includes which of the following:
    • An argument list containing properties and types 
    • A return type and property
  348. True/False  The features of a class can refer to both properties and operations.
    True
  349. Which of the following may be found in an attribute notation (select all that apply).

    A. Name
    C. Type  
    D. Visibility
    • A. Name 33.333% 
    • C. Type 33.333% 
    • D. Visibility 33.333%
  350. True/False   Whether an operation is public or private is indicated by either + for private or - for public.
    False
  351. Something a business must track or that participates in the business may generally be called _________.
    a business object
  352. Which of the following should be visible to other objects?
    Operations
  353. Another way to talk about a superclass is:
    Parent
  354. The acronynm OMG (when discussing UML) stands for which of the following:
    Object management Group
  355. Polymorphism refers to the ability of _________ to take many "shapes".
    objects & operations
  356. True/False  A subclass may add attributes, operations, and relationships to those inherited from the superclass.
    True
  357. True/False  Polymorphism allows a subclass to override operations of a superclass, thus specializing the operation for the subclass.
    True
  358. The UML standard is owned by which of the following?
    OMG
  359. An object of a subclass automatically;
    inherits all the attributes and operations of its superclass.
  360. If two objects belong to the same class, which of the following statements about those objects is true?
    The procedure for carrying out a specific operation will be the same for both objects.
  361. A superclass defines a method called findArea. A subclass of that superclass also defines a method called findArea, but the subclass method uses a different formula. This is an example of ________.
    polymorphism
  362. A "method" is:
    an operation
  363. Two things that must be remembered about specific objects are (select two):
    • Operations that my be performed by or on an object.
    • Values of an object's attributes.
  364. The ways objects may be related are:
    Association, Aggregation, Composition.
  365. True/False  Attributes and operations defined at the class level will be shared by all objects of that class.
    True
  366. True/False  Once a subclass is formed, no further inheritance from that subclass is allowed.
    False
  367. True/False  A subclass can effect state changes in superclass private members only through public, protected methods provided in the superclass and inherited into the subclass.
    True
  368. True/False  Subclasses provide the functionality and features inherited by superclasses.
    False
  369. True/False  A superclass's constructors are inherited into its subclasses.
    False
  370. True/False  Subclass methods can normally refer to protected and private members of the superclass simply by using the member names.
    False
  371. True/False  Protected members are accessible only to methods of their class and to methods of their subclasses.
    False
  372. True/False  To call the superclass default (no-argument) constructor explicitly, use the statement: super();
    True
  373. True/False  Assigning an object of a superclass to a subclass reference (without a cast) is a syntax error.
    True
  374. True/False  An explicit call to the superclass constructor must be provided as the first statement in the subclass constructor.
    False
  375. True/False  When a superclass method is overridden in a subclass, it is common to have the subclass version call the superclass version and do some additional work.
    True
  376. True/False  When creating subclasses, programmers must use discretion in choosing the proper superclass. Ideally, the superclass will not contain superfluous capabilities or information.
    True
  377. True/False  Method equals will accurately compare any two objects.
    False
  378. True/False  An object of class ImageIcon can be used to represent an image in a program.
    True
  379. True/False  Method setLabel specifies the text that should appear on a JLabel.
    False
  380. True/False  Unfortunately, polymorphic programs make it difficult to add new capabilities to a system.
    False
  381. True/False  Polymorphism enables objects of different classes that are related by a class hierarchy to be processed generically.
    True
  382. True/False  The major drawback to polymorphically designed programs is that they do not take into account the future addition or deletion of classes.
    False

    Polymorphically designed programs are extremely extensible and easily handle new classes that extend the same hierarchy of classes processed by the program. Review Section: 10.1 Introduction
  383. True/False  An abstract class declares a common interface for the various members of a class hierarchy. The abstract class contains methods that will be declared in the subclasses. All classes in the hierarchy can use this same set of methods through polymorphism.
    True
  384. True/False  Polymorphism is particularly effective for implementing layered software systems.
    True
  385. True/False  Casting superclass references to subclass references is known as downcasting.
    True
  386. True/False  If a subclass reference is assigned to a superclass variable, the variable must be cast back to the subclass before any subclass methods can be called with it.
    True

    Section: 10.3 Demonstrating Polymorphic Behavior
  387. True/False  Objects of abstract superclasses can be instantiated.
    False

    Only objects of concrete classes can be instantiated. Review Section: 10.4 Abstract Classes and Methods
  388. True/False  An abstract class cannot have instance data and non-abstract methods.
    False 

    An abstract class can have instance data and non-abstract methods. Review Section: 10.5 Case Study: A Payroll System Using Polymorphism
  389. True/False  Attempting to instantiate an object of an abstract class is a logic error.
    False
  390. True/False  A method that is declared final cannot be overridden in a subclass.
    True

    Section: 10.6 final Methods and Classes
  391. True/False  All methods in a final class must be explicitly declared final.
    False
  392. True/Final  If a class leaves one method in an interface undeclared, the class is implicitly declared by Java as an abstract class.
    False

    If a class leaves one method in an interface undeclared, the class becomes an abstract class and must be declared abstract in the first line of its class declaration. Review Section: 10.7 Case Study: Creating and Using Interfaces
  393. True/False  An interface is typically used in place of an abstract class when there is no default implementation to inherit.
    True
  394. Consider the examples below:

    A. "1234".
    B. "a string".
    C. 'a string'.
    D. integer.
    E. a string.

    Which could be the value of a Java variable of type String?

    a. A and B.
    b. B and E.
    c. B and C.
    d. C and D.
    A. C and D.
    (this multiple choice question has been scrambled)
  395. An anonymous String:

    A. has no value.
    B. is a string literal.
    C. can be changed.
    d. none of the above.
    B. is a string literal.
    (this multiple choice question has been scrambled)
  396. A String constructor cannot be passed variables of type:

    A. byte arrays.
    B. int arrays.
    C. Strings.
    D. char arrays.
    B. int arrays.
    (this multiple choice question has been scrambled)
  397. String objects are immutable. This means they:

    A. Cannot be deleted.
    B. Must be initialized.
    C. Cannot be changed.
    d. None of the above
    C. Cannot be changed.
    (this multiple choice question has been scrambled)
  398. The length of a string can be determined by:

    A. The String method strlen().
    B. The String instance variable length.
    C. The String method length().
    d. All of the above.
    C. The String method length().
    (this multiple choice question has been scrambled)
  399. How many String objects are instantiated by the following code segment (not including the literals)?

      String s1, output;
      s1 = "hello";
        output += "nThe string reversed is: " ;
        for ( int i = s1.length() - 1; i >= 0; i-- ) 
        output += s1.charAt( i ) + " " ;

    A. 5.
    B. 4.
    C. 1.
    D. 2.
    D. 2.
    (this multiple choice question has been scrambled)
  400. The statement

    s1.equalsIgnoreCase( s4 )

    is equivalent to which of the following?

    A. s1.regionMatches( true, s4, 0, s4.length );
    B. s1.regionMatches( 0, s4, 0, s4.length() );
    C. s1.regionMatches( 0, s4, 0, s4.length );
    D. s1.regionMatches( true, 0, s4, 0, s4.length() );
    D. s1.regionMatches( true, 0, s4, 0, s4.length() );
    (this multiple choice question has been scrambled)
  401. The statement;

    s1.startsWith( "art" )

    has the same result as which of the following?

    a. s1.regionMatches( 0, "art", 0, 3 );
    b. s2 = s1.getChars( 0, 3 );
                  s2.equals( "art" );
    c. s1.regionMatches( true, 0, "art", 0, 3 );
    d. All of the above
    d. All of the above
  402. For
      String c = "hello world";

    The Java statements;

    int i = c.indexOf( 'o' );
    int j = c.lastIndexOf( 'l' );

    will result in:
    A. i = 4 and j = 8.
    B. i = 5 and j = 9.
    C. i = 5 and j = 8.
    D. i = 4 and j = 9.
    D. i = 4 and j = 9.
    (this multiple choice question has been scrambled)
  403. For
      String c = "Hello. She sells sea shells";

    The Java statements;

    int i = c.indexOf( "ll" );
    int j = c.lastIndexOf( "ll" );

    will result in:
    A. i = 3 and j = 23.
    B. i = 2 and j = 25.
    C. i = 2 and j = 24.
    D. i = 3 and j = 24.
    C. i = 2 and j = 24.
    (this multiple choice question has been scrambled)
  404. For
      String c = "Now is the time for all";

    The Java statements;

    String i = c.substring( 7 );
    String j = c.substring( 4, 15 );

    will result in:
    A. i = "he time for all" and j = "s the time".
    B. i = "he time for all" and j = "is the time".
    C. i = "the time for all" and j = "is the time ".
    D. i = "the time for all" and j = "s the time".
    C. i = "the time for all" and j = "is the time ".
    (this multiple choice question has been scrambled)
  405. The String method substring returns:

    A. A char[].
    B. void.
    C. A char.
    D. A String.
    D. A String.
    (this multiple choice question has been scrambled)
  406. Consider the statements below:

    String a = "JAVA: ";
    String b = "How to ";
    String c = "Program";

    Which of the statements below will create the String r1 = "JAVA: How to Program"?

    A. String r1 = c.concat( b.concat( a ) );
    B. String r1 = c.concat( c.concat( b ) );
    C. String r1 = b.concat( c.concat( a ) );
    D. String r1 = a.concat( b.concat( c ) );
    D. String r1 = a.concat( b.concat( c ) );
    (this multiple choice question has been scrambled)
  407. ConsidertheString below:
             String r = "a toyota";

    Which of the following will create the String r1 = "a TOYOTa"?

    a. r1 = r.replace( "toyot", TOYOT" );
    b. r1 = r.replace( 't','T' );
              r1 = r.replace( 'o','0' );
              r1 = r.replace( 'y','Y' );
    c. r1 = r.replace( 't','T' ).replace( 'o', '0'      
                     ).replace( 'y', 'Y' );
    d. r1 = r.substring( 2, 4 ).toUpperCase();
    • c. r1 = r.replace( 't','T' ).replace( 'o', '0'            
    •             ).replace( 'y', 'Y' );
  408. Which of the following is not a method of class String?

    A. toCharacterArray.
    B. trim.
    C. toUpperCase.
    d. All of the above are methods of class String.
    A. toCharacterArray.
    (this multiple choice question has been scrambled)
  409. Which of the following will create a String different from the other three?

    a. String r = "123456"
    b. int i = 123;
        int j = 456;
        String r = String.valueOf(j) +    
             String.valueOf(i);
    c. int i = 123; 
        int j = 456;
        String r = String.valueOf(i) +    
             String.valueOf(j);
    d.int i = 123;

    int j = 456;

    String r = i + j;
    • b. int i = 123;    int j = 456;    String r =  
    •         String.valueOf(j) + String.valueOf(i);
  410. StringBuffer objects can be used in place of String objects if:

    a. The string data is not constant.
    b. The string data size may grow.
    c. Performance is not critical.
    d. All of the above.
    d. All of the above.
  411. Given the following declarations:

    StringBuffer buf;
    StringBuffer buf2 = new StringBuffer();
    String c = new String( "test" );

    Which of the following is not a valid StringBuffer constructor?

    A. buf = new StringBuffer();
    B. buf = new StringBuffer( buf2 );
    C. buf = new StringBuffer( c );
    D. buf = new StringBuffer( 32 );
    B. buf = new StringBuffer( buf2 );
    (this multiple choice question has been scrambled)
  412. Given the following declaration:

    StringBuffer buf = new StringBuffer();
    What is the capacity of buf?

    A. 16
    B. 20
    C. 10
    D. 0
    A. 16
    (this multiple choice question has been scrambled)
  413. Which of the following statements is true?

    A. Both a and b are true.
    B. The capacity of a StringBuffer cannot exceed its length.
    C. The length of a StringBuffer cannot exceed its capacity.
    D. The capacity of a StringBuffer is equal to its length.
    C. The length of a StringBuffer cannot exceed its capacity.
    (this multiple choice question has been scrambled)
  414. Given the following declarations:

    StringBuffer buffer = new StringBuffer( “Testing Testing” );
    buffer.setLength( 7 );
    buffer.ensureCapacity( 5 );

    Which of the following is true?

    A. buffer has length 15.
    B. buffer has capacity 31.
    C. buffer has content “Testin”.
    D. buffer has capacity 5.
    B. buffer has capacity 31.
    (this multiple choice question has been scrambled)
  415. Consider the statement below:

    StringBuffer sb1 = new StringBuffer( "a toyota" );

    Which of the following creates a String object with the value "toy"?

    a. String res = sb1.subString( 2, 5 );
    b. char dest[];
          sb1.getChars( 2, 4, dest, 0 );
          String res = new String( dest );
    c. char dest[] = new char[ sb1.length ];
          dest = sb1.getChars( 2, 5 );
          String res = new String( dest );
    d. char dest[] = new char[ sb1.length() ];
          dest = sb1.getChars( 0, 3 );

    String res = new String( dest );
    • b. char dest[];          
    •      sb1.getChars( 2, 4, dest, 0 );     
    •      String res = new String( dest );
  416. To find the character at a certain index position within a String, use the method:

    A. charAt, with the character you are searching for as an argument.
    B. getChars, with the index as an argument.
    C. getCharAt, with the index as an argument.
    D. charAt, with the index as an argument.
    D. charAt, with the index as an argument.
    (this multiple choice question has been scrambled)
  417. Which of the following creates the string of the numbers from 1 to 1000 most efficiently?

    a. String s;
         for ( int i = 1; i <= 1000; i++ )
         s += i;
    b. StringBuffer sb = new StringBuffer( 10 );
         for ( int i = 1; i <= 1000; i++ )
         sb.append( i );
         String s = new String( sb );
    c. StringBuffer sb = new StringBuffer( 3000 );
         for ( int i = 1; i <= 1000; i++ )
         sb.append( i );
         String s = new String( sb );
    d. All are equivalently efficient.
    • c. StringBuffer sb = new StringBuffer( 3000 );          
    •       for ( int i = 1; i <= 1000; i++ )     
    •       sb.append( i );     
    •       String s = new String( sb );
  418. Consider the statements below:

    StringBuffer sb = new StringBuffer( "a toyota" );
         sb.insert( 2, "landrover" );
         sb.delete( 11, 16 );
         sb.insert( 11, " " );

    The StringBuffer contents at the end of this segment will be:

    A. a landrover a.
    B. a landrov a.
    C. a landrover toy a.
    D. a landrovertoyota.
    A. a landrover a.
    (this multiple choice question has been scrambled)
  419. Which of the following are static Character methods?

    A. Character.isDigit( char c );
    B. Character.equals( char c );
    C. Character.hashcode( char c );
    d. All of the above.
    A. Character.isDigit( char c );
    (this multiple choice question has been scrambled)
  420. Which class is not a type-wrapper class?

    A. Byte
    B. Int
    C. Character
    D. Double
    B. Int
    (this multiple choice question has been scrambled)
  421. Consider the Java segment:

    String line1 = new String( "c = 1 + 2 + 3" ) ;
    StringTokenizer tok = new StringTokenizer( line1, delimArg );
    For the String line1 to have 4 tokens, delimArg should be:

    A. String delimArg = "+=";
    B. String delimArg = "c+";
    C. String delimArg = "123"
    D. String delimArg = " ";
    A. String delimArg = "+=";
    (this multiple choice question has been scrambled)
  422. Consider the Java segment:

    String line1 = new String( "c = 1 + 2 + 3" ) ;
    StringTokenizer tok = new StringTokenizer( line1 );
    int count = tok.countTokens();

    The value of count is:

    A. 4.
    B. 8.
    C. 13.
    D. 7.
    D. 7.
    (this multiple choice question has been scrambled)
  423. Consider the Java segment:

    String line1 = new String( "c = 1 + 2 + 3" ) ;
    StringTokenizer tok = new StringTokenizer( line1, "+=" );
    String foo = tok.nextToken();
    String bar = tok.nextToken();

    The values of foo and bar are:

    A. foo is “c ”, bar is “ 1 ”.
    B. foo is “ = ”,bar is “ + ”.
    C. foo is “c”, bar is “ ”.
    D. foo is “c ”, bar is “ = ”.
    A. foo is “c ”, bar is “ 1 ”.
    (this multiple choice question has been scrambled)
  424. Which of the following is not a word character?

    A. 0
    B. _
    C. w
    D. &
    D. &
    (this multiple choice question has been scrambled)
  425. Which of the following statements is true?

    A. [^Z] is the same as [A~Y].
    B. Ranges of characters can be represented by placing a ~ between two characters.
    C. Both “A*” and “A+” will match “A”, but only “A*” will match an empty string.
    d. All of above.
    C. Both “A*” and “A+” will match “A”, but only “A*” will match an empty string.
    (this multiple choice question has been scrambled)
  426. Which of the Java strings represent the regular expression ,s*?

    A. “,s*”.
    B. “.s*”.
    C. “,s*”.
    D. “,s*”.
    A. “,s*”.
    (this multiple choice question has been scrambled)
  427. Which of the following statements is true?

    a. Class Matcher provides methods find, lookingAt, replaceFirst and replaceAll.
    b. Method matches (from class String, Pattern or Matcher) will return true only if the entire search object matches the regular expression.
    c. Methods find and lookingAt (from class Matcher) will return true if a portion of the search object matches the regular expression.
    d. All of above.
    d. All of above.
  428. Which of the following is not a specific GUI component (control or widgit)?

    A. List.
    B. String.
    C. Menu.
    D. Label.
    B. String.
    (this multiple choice question has been scrambled)
  429. Which of the following is not a benefit of using Swing GUI components?

    A. Most Swing components are written completely in Java
    B. Swing components allow the user to specify a uniform look and feel across all platforms.
    C. Most Swing components are heavyweight.
    D. Swing components allow the user to change the look and feel while the program is running.
    C. Most Swing components are heavyweight.
    (this multiple choice question has been scrambled)
  430. Which pair of words does not complete the sentence below correctly?
    A _______ is a ________.

    a. Container/Component.
    b. JComponent/Container.
    c. Component/Object.
    d. Container/JPanel.
    d. Container/JPanel.
  431. Which of the following is not a valid constructor for a JLabel?

    A. JLabel( String text, int horizontalAlignment );
    B. JLabel( int, horizontalAlignment, Icon image );
    C. JLabel( Icon image );
    D. JLabel( String text, Icon image, int horizontalAlignment );
    B. JLabel( int, horizontalAlignment, Icon image );
    (this multiple choice question has been scrambled)
  432. Which of the following steps is not required to use a JLabel as a GUI component?

    A. Instantiate the JLabel.
    B. Initialize the JLabel text.
    C. Add to the contentPane().
    D. Declare a reference to a JLabel.
    B. Initialize the JLabel text.
    (this multiple choice question has been scrambled)
  433. Which of the following generate GUI events?

    A. Calling an itemListener.
    B. Selecting an item from a menu.
    C. Calling an adjustmentListener.
    D. Typing in a text field.
    a. A and B.
    b. B and C.
    c. C and D.
    d. A and D.
    D. A and B.
    (this multiple choice question has been scrambled)
  434. Consider the abstract superclass below:        
        public abstract class Foo {                              
                               private int a;                                      
     
                                public int b;                
            public Foo( int aVal, int bVal )                                    
                      {                                 
                          a = aVal;                                 
                          b = bVal;                             }            
                   public abstract int calculate();      
               }

    Any concrete subclass that extends class Foo;

    A. Must implement a method called calculate().
    B. Both a and b.
    C. Neither a nor b.
    D. Will not be able to access the instance variable a.
    B. Both a and b.
    (this multiple choice question has been scrambled)
  435. Which of the following completes the sentence below correctly?

    A(n) _______ is a(n) __________.

    a.InputEvent/MouseEvent.
    b.ActionEvent/AdjustmentEvent.
    c.FocusEvent/WindowEvent.
    d.ContainerEvent/ComponentEvent.
    d.ContainerEvent/ComponentEvent.
  436. Which of the following is not necessary to use the event delegation model?

    A. An event listener must be registered.
    B. An event handler must be implemented.
    C. The appropriate interface must be registered.
    D. The appropriate interface must be implemented.
    C. The appropriate interface must be registered.
    (this multiple choice question has been scrambled)
  437. Which of the following statements about JTextFields and JPasswordFields is not true?

    A. JPasswordField(String text,int columns)isavalidconstructor.
    B. JTextField(String text,int columns)isavalidconstructor.
    C. A JTextField is a JTextComponent.
    D. A JTextField is a JPasswordField.
    D. A JTextField is a JPasswordField.
    (this multiple choice question has been scrambled)
  438. JTextField and JPasswordField events are handled using which interfaces?

    A. They use TextFieldListener and ActionListener interfaces respectively.
    B. Both use the ActionListener interface.
    C. Both use the TextComponentListener interface.
    D. Both use the TextFieldListener interface.
    B. Both use the ActionListener interface.
    (this multiple choice question has been scrambled)
  439. Which of the following choices completes the sentence correctly?

    A ____ is a(n) _____

    a. ToggleButton/JCheckBox.
    b. ToggleButton/JRadioButton.
    c. JButton/ToggleButton.
    d. JButton/AbstractButton.
    d. JButton/AbstractButton.
  440. The method setRolloverIcon is used to:

    A. Handle a mouse event.
    B. Change the button icon.
    C. Change the button text.
    d. All of the above.
    B. Change the button icon.
    (this multiple choice question has been scrambled)
  441. Which of the following is stateless?

    A. JCheckBox.
    B. JButton.
    C. JRadioButton.
    D. JToggleButton.
    B. JButton.
    (this multiple choice question has been scrambled)
  442. Which of the following does not generate an item event when pressed?

    A. JButton.
    B. JCheckBox.
    C. JRadioButton.
    D. JToggleButton.
    A. JButton.
    (this multiple choice question has been scrambled)
  443. When a JComboBox is clicked on:

    A. The JComboBox expands to a list.
    B. An ItemEvent is generated.
    C. A scrollbar is always generated.
    D. An ActionEvent is generated.
    A. The JComboBox expands to a list.
    (this multiple choice question has been scrambled)
  444. The setMaximumRowCount method is used for:

    A. JComboBox.
    B. JToggleButton.
    C. JRadioButton.
    D. Button.
    A. JComboBox.
    (this multiple choice question has been scrambled)
  445. A JScrollPane is provided for which of the following:

    a. JToggleButton.
    b. JRadioButton.
    c. JList.
    d. None of the above.
    d. None of the above.
  446. Selecting a JList item creates:

    A. An ActionEvent.
    B. A ListSelectionEvent.
    C. A ListActionEvent.
    D. A ListItemEvent.
    B. A ListSelectionEvent.
    (this multiple choice question has been scrambled)
  447. Consider the list below:

    January
    February
    March
    April
    May
    June
    July
    August
    September
    November
    December

    What type of JList selection mode would allow the user to select March, June, and July in one step.

    A. MULTIPLE_INTERVAL_SELECTION.
    B. SINGLE_SELECTION. 
    C. SINGLE_INTERVAL_SELECTION.
    d. All of the above.
    A. MULTIPLE_INTERVAL_SELECTION.
    (this multiple choice question has been scrambled)
  448. Which of the following objects can not trap mouse events?

    A. JTextField.
    B. JButton.
    C. ButtonGroup.
    D. JComponent.
    C. ButtonGroup.
    (this multiple choice question has been scrambled)
  449. Which of the following is a MouseMotionListener method?

    A. mousePressed.
    B. mouseClicked.
    C. mouseExited.
    D. mouseDragged.
    D. mouseDragged.
    (this multiple choice question has been scrambled)
  450. Which of the following statements about adapters is false?

    A. Programmers override selected adapter methods.
    B. An adapter class implements an interface.
    C. Programmers provide a default (empty) implementation of every method in the interface.
    D. A ComponentAdaptor is a ComponentListener.
    C. Programmers provide a default (empty) implementation of every method in the interface.
    (this multiple choice question has been scrambled)
  451. A one-button mouse can simulate pushing the middle button on a three-button mouse by:

    A. Holding the alt-key while clicking the mouse button.
    B. Holding the shift-key while clicking the mouse button.
    C. Holding the meta-key while clicking the mouse button.
    D. Holding the ctrl-key while clicking the mouse button.
    A. Holding the alt-key while clicking the mouse button.
    (this multiple choice question has been scrambled)
  452. Which of the following is not a KeyListener method?

    A. keyRelease.
    B. keyPressed.
    C. keyClicked.
    D. keyTyped.
    C. keyClicked.
    (this multiple choice question has been scrambled)
  453. The Shift key is a _________ key.

    A. Output.
    B. Action.
    C. Modifier.
    d. None of the above.
    C. Modifier.
    (this multiple choice question has been scrambled)
  454. Which layout manager is the default for JFrame?

    A. FlowLayout. 
    B. BorderLayout.
    C. GridLayout.
    d. None of the above.
    B. BorderLayout.
    (this multiple choice question has been scrambled)
  455. The layout manager that allows alignment to be controlled is:

    A. BorderLayout.
    B. FlowLayout.
    C. GridLayout.
    d. None of the above.
    B. FlowLayout.
    (this multiple choice question has been scrambled)
  456. FlowLayout is:

    A. An abstract class.
    B. The simplest layout manager.
    C. A way of organizing components vertically.
    D. Left-aligned by default.
    B. The simplest layout manager.
    (this multiple choice question has been scrambled)
  457. BorderLayout implements interface:

    A. LayoutManager2.
    B. FlowLayout.
    C. Layout.
    D. ActionListener.
    A. LayoutManager2.
    (this multiple choice question has been scrambled)
  458. The BorderLayout layout manager:

    A. Divides an area into five regions: UP, DOWN, LEFT, RIGHT, and MIDDLE.
    B. Divides an area into five regions: NORTH, SOUTH, EAST, WEST, and CENTER.
    C. Orders components horizontally.
    D. Orders components vertically.
    B. Divides an area into five regions: NORTH, SOUTH, EAST, WEST, and CENTER.
    (this multiple choice question has been scrambled)
  459. The class GridLayout constructs _________ to hold components.

    A. A square grid with the same number of rows as columns.
    B. A grid with m rows and n columns.
    C. A vertical grid with one column.
    D. A horizontal grid with one row.
    B. A grid with m rows and n columns.
    (this multiple choice question has been scrambled)
  460. When components are added to a container with a GridLayout, the component:

    A. Fills in row x, column y if x and y are two integers passed to the Container method add.
    B. Fills the next spot in the row, continuing in the first position of the next row if the current row is full.
    C. Fills the next spot in a column, continuing in the first position of the next column if the column is full.
    D.Fills in a random empty position in the grid.
    B. Fills the next spot in the row, continuing in the first position of the next row if the current row is full.
    (this multiple choice question has been scrambled)
  461. Which of the following statements about JPanels is not true?

    A. A JPanel has a fixed size.
    B. A JPanel is a Container.
    C. Mouse events can be trapped for a JPanel.
    D. A JPanel is a JComponent.
    A. A JPanel has a fixed size.
    (this multiple choice question has been scrambled)
  462. ________________ is a form of software reusability in which new classes acquire the members of existing classes and embellish those classes with new capabilities.
    Inheritance
  463. A superclass's ________________ members can be accessed in the superclass declaration and in subclass declarations.
    public and protected
  464. In a _____________________ relationship, an object of a subclass can also be treated as an object of it's superclass.
    is-a or inheritance
  465. In a ____________________ relationship, a class object has references to objects of other classes as members.
    has-a or composition
  466. In single inheritance, a class exists in a ______________ relationship with its subclasses.
    hierarchical
  467. List five common examples of exceptions;
    • 1. memory exhaustion
    • 2. array index out of bounds
    • 3. arithmetic overflow
    • 4. division by zero
    • 5. invalid method parameters
  468. Give several reasons why exception-handling techniques should not be used for conventional program control;
    • a) Exception handling is designed to handle infrequently occurring situations that often result in program termination, not situations that arise all the time.
    • b) Flow of control with conventional control structures is generally clearer and more efficient than with exceptions.  
    • c) The additional exceptions can get in the way of genuine error-type exceptions.
    • d) It becomes more difficult for you to keep track of the larger number of exception cases.
  469. Why are exceptions particularly appropriate for dealing withe errors produced by methods of classes in the Java API?
    It's unlikely that methods of classes in the Java API could perform error processing that would meet the unique needs of all users.
  470. What is a resource leak?
    A "resource leak" occurs when an executing program does not properly release a resource when it's no longer needed.
  471. If no exceptions are thrown in a try block, where does control proceed to when the try block completes execution?
    The catch blocks for that try statement are skipped, and the program resumes execution after the last catch block.  If there's a finally block, it's executed first; then the program resumes execution after the finally block.
  472. Give a key advantage of using catch(Exception exceptionName);
    The form catch(Exception exceptionName) catches any type of exception thrown in a try block.  An advantage is that known thrown exception can slip by without being caught.  You can then decide to handle the exception or possibly rethrow it.
  473. Should a conventional application catch error objects?  Explain.
    Errors are usually serious problems with the underlying Java system; most programs will not want to catch errors because they will not be able to recover from them.
  474. What happens if no catch handler matches the type of a thrown object?
    This causes the search for a match to continue in the next enclosing try statement.  If there's a finally block, it will be executed before the exception goes to the next enclosing try statement.  If there are no enclosing try statements for which there are matching catch blocks and the exceptions are declared (or unchecked), a stack trace is printed and the current thread terminates early.  If the exceptions are checked, but not caught or declared, compilation errors occurs.
  475. All of the following are true about classes except;

    A) The first class in any C++ program is main
    B) Classes have attributes and behaviors
    C) A class's functions hide from the user the complex tasks they perform
    D) An object must be created from a class before it can be used
    A) The first class in any C++ program is main
    (this multiple choice question has been scrambled)
  476. Function headers contain all of the following except:

    A) Parenthesis
    B) Return type
    C) Left brace
    D) Name of function
    C) Left brace
    (this multiple choice question has been scrambled)
  477. C++ functions other than main are executed:

    A) When they are explicitly called by another function
    B) Before main executes
    C) Never
    D) After main completes execution
    A) When they are explicitly called by another function
    (this multiple choice question has been scrambled)
  478. An object creation expression contains:

    a) The name of the class
    b) Parenthesis
    c) The name of the object
    d) All of the above
    d) All of the above
  479. Polymorphism enables you to;

    A) program in the specific
    B) absorb attributes and behavior from previous classes
    C) program in the general
    D) hide information from the user
    C) program in the general
    (this multiple choice question has been scrambled)
  480. Calling a member function of an object requires which item?

    A) The class name
    B) Open and close braces
    C) The dot separator
    d) None of the above
    C) The dot separator
    (this multiple choice question has been scrambled)
  481. In the UML, the top compartment of the rectangle modeling a class contains:

    A) The class's name
    B) The class's behavior
    C) The class's attributes
    d) All of the above
    A) The class's name
    (this multiple choice question has been scrambled)
  482. Which of the following is an example of a functionality that should not be "factored out" to a superclass?

    A) All animals lay eggs, except for mammals
    B) All vehicle know how to start and stop
    C) Both ducks and geese are birds that know how to start flying from the water
    D) All paints have a color
    A) All animals lay eggs, except for mammals
    (this multiple choice question has been scrambled)
  483. What is the name of the values the method call passes to the method for the parameters?

    A) Values
    B) Arguments
    C) References
    D) Object
    B) Arguments
    (this multiple choice question has been scrambled)
  484. Assuming that text is a variable of type string, what will be the contents of text after the statement cin >> text; is executed if the user types “Hello World!” and then presses Enter?

    A) Hello
    B) H
    C) Hello World!
    D) Hello World
    A) Hello
    (this multiple choice question has been scrambled)
  485. Multiple parameters are separated by what symbol?

    A) The dot separator
    B) Commas
    C) Parenthesis
    D) Braces
    B) Commas
    (this multiple choice question has been scrambled)
  486. Attributes of a class are also known as;

    A) local variable
    B) classes
    C) constructors
    D) data members
    D) data members
    (this multiple choice question has been scrambled)
  487. Which of the following statements is (are) true?

    A) We can use inheritance to customize existing software
    B) A superclass specifies commonality
    C) A subclass can be modified without modifying its superclass
    D) A superclass can be modified without modifying subclasses

    a) A, B and C
    b) A, B and D
    c) All of the above
    d) None of the above
    D) All of the above
    (this multiple choice question has been scrambled)
  488. An advantage of inheritance is that;

    A) All methods can be inherited
    B) Objects of a subclass can be treated like objects of their superclass
    C) All instance variables can be uniformly accessed by subclasses and superclasses
    d) None of the above
    B) Objects of a subclass can be treated like objects of their superclass
    (this multiple choice question has been scrambled)
  489. What is the default initial value of a String?

    A) default
    B) null
    C) "default"
    D) ""
    B) null

    Textbook Page 82
    (this multiple choice question has been scrambled)
  490. What type of member functions allow a client of a class to assign values to private data members?

    A) assign member functions
    B) set member functions
    C) client member functions
    D) access member functions
    B) set member functions
    (this multiple choice question has been scrambled)
  491. A default constructor has how many parameters?

    A) Variable
    B) 1
    C) 2
    D) 0
    D) 0
    (this multiple choice question has been scrambled)
  492. A constructor can specify the return type;

    A) string
    B) void
    C) int
    D) A constructor cannot specify a return type
    D) A constructor cannot specify a return type
    (this multiple choice question has been scrambled)
  493. The compiler will implicitly create a default constructor if:

    A) the programmer specifically requests that a compiler do so
    B) the class already defines a default constructor
    C) the class does not define any constructors
    D) the class does not contain any data members
    C) the class does not define any constructors
    (this multiple choice question has been scrambled)
  494. Inheritance is also known as the;

    A) "is-a" relationship
    B) "knows-a" relationship
    C) "uses-a" relationship
    D) "has-a" relationship
    A) "is-a" relationship
    (this multiple choice question has been scrambled)
  495. Which statement is false?

    A) An enum declaration is a comma-separated list of enum constants and may optionally include other components of traditional classes, such as constructors, fields and methods.
    B) Any attempt to create an object of an enum type with operator and new results in a compilation error.
    C) An enum constructor can specify any number of parameters.
    D) An enum constructor cannot be overloaded.
    D) An enum constructor cannot be overloaded.

    Textbook Page 331 - An enum constructor CAN be overloaded.
    (this multiple choice question has been scrambled)
  496. A header file is typically given the filename extension;

    A) .hdr
    B) .cpp
    C) .h
    D) .header
    C) .h
    (this multiple choice question has been scrambled)
  497. Assuming that GradeBook.h is found in the current directory and the iostream header file is found in the C++ Standard Library header file directory, which of the following preprocessor directives will fail to find its desired header file?

    A) #include.
    B) #include.
    C) #include "GradeBook.h".
    D) #include "iostream".
    A) #include.
    (this multiple choice question has been scrambled)
  498. In the source-code file containing a class’s member function definitions, each member function definition must be tied to the class definition by preceding the member function name with the class name and ::, which is known as the:

    A) member definition linker
    B) binary scope resolution operator
    C) class implementation connector
    D) source code resolver
    B) binary scope resolution operator
    (this multiple choice question has been scrambled)
  499. When compiling a class’s source code file (which does not contain a main function), the information in the class’s header file is used for all of the following, except;

    A) Determining the correct amount of memory to allocate for each object of the class.
    B) Ensuring that the first line of each member function matches its prototype.
    C) Ensuring that each member function knows about the class's data members and other member functions.
    d) All of the above are uses that the compiler has for the header file information.
    A) Determining the correct amount of memory to allocate for each object of the class.
    (this multiple choice question has been scrambled)
  500. When a client code programmer uses a class whose implementation is in a separate file from its interface, that implementation code is merged with the client’s code during the;

    A) Linking phase
    B) Executing phase
    C) Compiling phase
    D) Programming phase
    A) Linking phase
    (this multiple choice question has been scrambled)
  501. Composition is sometimes referred to as a(n) __________.

    A) has-a relationship
    B) many-in-one relationship
    C) is-a relationship
    D) one-to-many relationship
    A) has-a relationship
    (this multiple choice question has been scrambled)
  502. When implementing a method, use the class's set and get methods to access the class's  _____________ data.

    A) private
    B) protected
    C) public
    d) All of the above
    A) private
    (this multiple choice question has been scrambled)
  503. Non-abstract classes are called;

    A) implementable classes
    B) instance classes
    C) real classes
    D) concrete classes
    D) concrete classes
    (this multiple choice question has been scrambled)
  504. Polymorphism allows for specifics to be dealt with during;

    A) execution
    B) debugging
    C) compilation
    D) programming
    A) execution
    (this multiple choice question has been scrambled)
  505. To execute multiple statements when an if statement’s condition is true, enclose those statements in a pair of;

    A) Square brackets, [].
    B) Angle brackets, <>.
    C) Parenthesis, ().
    D) Braces,{}.
    D) Braces,{}.
    (this multiple choice question has been scrambled)
  506. Assuming that the string object text contains the string “Hello!!!”, the expression text.substr( 2 , 5 ) would return a string object containing the string;

    A) "ello"
    B) "llo!"
    C) "llo!!"
    D) "ello!"
    B) "llo!"
    (this multiple choice question has been scrambled)
  507. A solid line representing an association between two classes can be accompanied by any of the following details, except;

    A) A role name for one or both of the objects
    B) A name and direction for the association
    C) A number near the end of each one indication multiple values
    D) An aggregation relationship with another association line
    D) An aggregation relationship with another association line
    (this multiple choice question has been scrambled)
  508. A composition or “has-a” relationship is represented in the UML by;

    A) Making the association line dashed
    B) Making the association line bolded
    C) Attaching a solid diamond to the association line
    D) Attaching a solid triangle to the association line
    C) Attaching a solid diamond to the association line
    (this multiple choice question has been scrambled)
  509. A(n) __________ class cannot be instantiated.

    A) polymorphic
    B) final
    C) abstract
    D) concrete
    C) abstract
    (this multiple choice question has been scrambled)
  510. Which statement best describes the relationship between superclass and subclass types?

    A) A subclass reference can be assigned to a superclass variable and a superclass reference can be assigned to a subclass variable.
    B) A superclass reference can be assigned to a subclass variable, but a subclass reference cannot be assigned to a superclass variable. 
    C) A subclass reference cannot be assigned to a superclass variable and a superclass reference cannot be assigned to a subclass variable.
    D) A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
    D) A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
    (this multiple choice question has been scrambled)
  511. __________________ is a form of software reusability in which new classes acquire the members of existing classes with new capabilities.
    Inheritance
  512. True/False;  A "has-a" relationship is implemented via inheritance.
    False
  513. Java was originally developed for;

    A) Operating systems development
    B) Intelligent consumer devices
    C) Personal computers
    D) Distributed computing
    B) Intelligent consumer devices
    (this multiple choice question has been scrambled)
  514. Which of the following is not a valid Java identifier?

    A) width
    B) my Value
    C) m_x
    D) $_AAA1
    B) my Value

    Java identifiers may not contain blanks (spaces).
    (this multiple choice question has been scrambled)
  515. Which is the output of the following statement;

    System.out.print("Hello ");
    System.out.println("World");

    A) HelloWorld
    B) Hello
    C) Hello World
    World
    d) World
    Hello
    C) Hello World
    (this multiple choice question has been scrambled)
  516. Which of the following is a variable declaration statement?

    A) public static void main(String args[])
    B) import java.util.Scanner
    C) // first string entered by user
    D) int total;
    D) int total;
    (this multiple choice question has been scrambled)
  517. A class instance creation expression contains;

    a) Parentheses
    b) The new keyword
    c) The name of the class
    d) All of the above
    d) All of the above
  518. Which of the following should usually be private?

    A) Constructors
    B) Variables (or fields)
    C) Methods
    d) All of the above
    B) Variables (or fields)
    (this multiple choice question has been scrambled)
  519. What is the default initial value of a String instance variable?

    A) "default"
    B) null
    C) default
    D) ""
    B) null

    Textbook page 82
    (this multiple choice question has been scrambled)
  520. Which of the following is not a control structure?

    A) Declaration structure
    B) Selection structure
    C) Sequence structure
    D) Repetition structure
    A) Declaration structure
    (this multiple choice question has been scrambled)
  521. What is output by the following Java code segment?

    int temp;
    temp = 200;

       if ( temp > 90 )
          System.out.println( "This porridge is too  
                           hot." );

       if ( temp < 70 )
          System.out.println( "This porridge is too
                           cold." );

       if ( temp == 80 )
          System.out.println( "This porridge is just
                           right!" );

    A) This porridge is just right!
    B) This porridge is too hot.
    C) This porridge is too cold.
    d) None of the above
    B) This porridge is too hot.
    (this multiple choice question has been scrambled)
  522. How many times is the body of the loop below executed?

           int counter;
           counter = 1;

            while ( counter > 20 )
    {
    // body of loop
    counter = counter + 1;
    } // end while

    A. 21.
    B. 20.
    C. 0.
    D. 19.
    C. 0.

    Nothing increments the counter so it is always = 1 and never > 20.
    (this multiple choice question has been scrambled)
  523. Which statement is true?

    a. Dividing two integers results in integer division.
    b. With integer division, any fractional part of the calculation is lost.
    c. With integer division, any fractional part of the calculation is truncated.
    d. All of the above.
    d. All of the above.
  524. Suppose method1 is declared as;
         void method1(int a, float b)

    Which of the following methods correctly overloads method1?

    A) void method1(float a, int b)
    B) void method2(int a, float b)
    C) void method2(float a, int b)
    D) void method1(int b, float a)
    A) void method1(float a, int b)
    (this multiple choice question has been scrambled)
  525. What does the expression x %= 10 do?

    A. Divides x by 10 and stores the integer result in x.
    B. Divides x by 10 and stores the remainder in x.
    C. Adds 10 to the value of x, and stores the result in x.
    d. None of the above.
    B. Divides x by 10 and stores the remainder in x.
    (this multiple choice question has been scrambled)
  526. Consider the classes below:

    public class TestA
    {
    public static void main( String args[] )
    {
    int x = 2, y = 20, counter = 0;

    for ( int j = y % x; j < 100; j += ( y / x ) )
    counter++;
    } // end main
    } // end class TestA

    public class TestB
    {
    public static void main(String args[])
    {
    int counter = 0;

    for ( int j = 10; j > 0; --j )
    ++counter;
    } // end main
    } // end class TestB

    Which of the following statements is true?

    A. Neither (a) nor (b) is true.
    B. The value of counter will be different at the end of each for loop for each class.
    C. The value of j will be the same for each loop for all iterations
    D. Both (a) and (b) are true.
    A. Neither (a) nor (b) is true.
    (this multiple choice question has been scrambled)
  527. Which of the following statements about a do¡Kwhile repetition statement is true?

    A. The body of a do¡Kwhile loop is always executed at least once.
    B. The body of a do¡Kwhile loop is executed only once.
    C. The body of a do¡Kwhile loop is executed only if the terminating condition is true.
    d. None of the above
    A. The body of a do¡Kwhile loop is always executed at least once.
    (this multiple choice question has been scrambled)
  528. What do the following statements do?

    double[] array;
    array = new double[14];

    A) Create a double array containing 13 elements.
    B) Create a double array containing 14 elements.
    C) Declare but do not create a double array.
    D) Create a double array containing 15 elements.
    B) Create a double array containing 14 elements.
    (this multiple choice question has been scrambled)
  529. Consider the code segment below.

    if ( gender == 1 )
    {
    if ( age >= 65 )
    ++seniorFemales;
    } // end if

    This segment is equivalent to which of the following?

    a. if ( gender == 1 || age >= 65 )
    ++seniorFemales;
    b. if ( gender == 1 && age >= 65 )
    ++seniorFemales;
    c. if ( gender == 1 AND age >= 65 )
    ++seniorFemales;
    d. if ( gender == 1 OR age >= 65 )
    ++seniorFemales;
    b. if ( gender == 1 && age >= 65 )++seniorFemales;
  530. Which is a correct static method call of Math class method sqrt?

    A. Math.sqrt( 900 );.
    B. math.sqrt( 900 );.
    C. Math math = new Math(); math.sqrt( 900 );.
    D. sqrt( 900 );.
    A. Math.sqrt( 900 );.
    (this multiple choice question has been scrambled)
  531. Declaring main as ________ allows the JVM to invoke main without creating an instance of the class.

    A. void.
    B. final.
    C. public.
    D. static.
    D. static.
    (this multiple choice question has been scrambled)
  532. Which statement is not true;

    A. The Java API helps programmers avoid "reinventing the wheel."
    B. The Java API consists of packages.
    C. The class javax.swing.JApplet is part of the Java API.
    D. The Java API consists of import declarations.
    D. The Java API consists of import declarations.
    (this multiple choice question has been scrambled)
  533. Which statement below could be used to simulate the outputs of rolling a six-sided die? Suppose randomNumbers is a Random object.

    A. 1 + randomNumbers.nextInt( 6 );
    B. 1 + randomNumbers.nextInt( 2 );
    C. 3 + randomNumbers.nextInt( 3 );
    D. 6 + randomNumbers.nextInt( 1 );
    A. 1 + randomNumbers.nextInt( 6 );
    (this multiple choice question has been scrambled)
  534. Suppose method1 is declared as;

    void method1 ( int a, float b )

    Which of the following methods correctly overloads method1?

    A. void method1 ( int b, float a ).
    B. void method2 ( float a, int b ).
    C. void method1 ( float a, int b ).
    D. void method2 ( int a, float b ).
    C. void method1 ( float a, int b ).
    (this multiple choice question has been scrambled)
  535. Consider the array:

    s[ 0 ] = 7
    s[ 1 ] = 0
    s[ 2 ] = -12
    s[ 3 ] = 9
    s[ 4 ] = 10
    s[ 5 ] = 3
    s[ 6 ] = 6

    The value of s[ s[ 6 ] - s[ 5 ] ] is;

    A. 0.
    B. 3.
    C. 9.
    D. 0.
    C. 9.
    (this multiple choice question has been scrambled)
  536. Consider the program below:

    public class Test
    {
    public static void main( String[] args )
    {
    int[] a;
    a = new int[ 10 ];

    for ( int i = 0; i < a.length; i++ )
    a[ i ] = i + 2;
    int result = 0;
    for ( int i = 0; i < a.length; i++ )
    result += a[ i ];
    System.out.printf( "Result is: %dn", result );
    } // end main
    } // end class Test

    The output of this program will be:

    a. Result is: 62.
    b. Result is: 64.
    c. Result is: 65.
    d. Result is: 67.
    c. Result is: 65.
  537. Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray is called with the method call changeArray( items, items[ 2 ] ), what values are stored in items after the method has finished executing?

    public static void changeArray( int[] passedArray, int value )
    {
    passedArray[ value ] = 12;
    value = 5;
    } // end method changeArray

    A. 0, 2, 12, 6, 8.
    B. 0, 2, 4, 6, 5.
    C. 0, 2, 5, 6, 12.
    D. 0, 2, 4, 6, 12.
    D. 0, 2, 4, 6, 12.
    (this multiple choice question has been scrambled)
  538. Which of the following should usually be private?

    A. Methods.
    B. Constructors.
    C. Variables (or fields).
    d. All of the above.
    C. Variables (or fields).
    (this multiple choice question has been scrambled)
  539. When should a program explicitly use the this reference?

    A. Accessing a local variable.
    B. Accessing a public variable.
    C. Accessing a private variable.
    D. Accessing a field that is shadowed by a local variable.
    A. Accessing a local variable.
    (this multiple choice question has been scrambled)
  540. When implementing a method, use the class's set and get methods to access the class's ________ data.

    A. private.
    B. protected.
    C. public.
    d. All of the above.
    A. private.
    (this multiple choice question has been scrambled)
  541. Attempting to access an array element out of the bounds of an array, causes a(n)________________________.

    A) ArrayElementOutOfBoundsException
    B) ArrayOutOfBoundsException
    C) ArrayIndexOutOfBoundsException
    D) ArrrayException
    C) ArrayIndexOutOfBoundsException
    (this multiple choice question has been scrambled)
  542. Assume array items contains the values 0, 2, 4, 6 and 8. Which of the following set of
    statements uses the enhanced for loop to display each value in array items?

    a) for ( int i : items )
       System.out.printf( "%dn", items[ i ] );

    b) for ( int i : items )
       System.out.printf( "%dn", i);

    c) for ( int i = 0 : items.length )
       System.out.printf( "%dn", items[ i ] );

    d) for ( int i = 0 : items.length;i++ )   System.out.printf( "%dn",items[ i ] );
    b) for ( int i : items )   System.out.printf( "%dn", i);
  543. Consider the array declaration:

    int s[] = {7, 0, -12,
    9, 10, 3, 6};

    What is the value of

     s[ s[ 6 ] - s[ 5 ] ]

    A) 0
    B) 3
    C) 9
    D) -12
    C) 9
    (this multiple choice question has been scrambled)
  544. A programmer must do the following before
    using an array:

    A) declare then create the array.
    B) create then declare the array.
    C) declare then reference the array.
    D) create then reference the array.
    A) declare then create the array.
    (this multiple choice question has been scrambled)
  545. Which expression adds 1 to the element of
    array arrayName at index i?

    A) arrayName[ i++ ]
    B) arrayName++[ i ]
    C) ++arrayName[ i ]
    C) ++arrayName[ i ]
    (this multiple choice question has been scrambled)
  546. Sending a message to an object means that;

    A) You access a variable of the object
    B) Neither a nor b
    C) You call a method of the object
    D) Both a and b
    C) You call a method of the object

    Textbook - Page 12
    (this multiple choice question has been scrambled)
  547. Consider integer array values, which contains 5 elements. Which statements successfully swap the contents of the array at index 3 and index 4?

    a) values[ 3 ] = values[ 4 ];
        values[ 4 ] = values[ 3 ];

    b) values[ 4 ] = values[ 3 ];
        values[ 3 ] = values[ 4 ];

    c) int temp = values[ 3 ];
        values[ 3 ] = values[ 4 ];
        values[ 4 ] = temp;

    d) int temp = values[ 3 ];
        values[ 3 ] = values[ 4 ];
        values[ 4 ] = values[ 3 ];
    • c) int temp = values[ 3 ];   
    •     values[ 3 ] = values[ 4 ];   
    •     values[ 4 ] = temp;
  548. Assume a class, Book, has been defined. Which set of statements creates an array of Book objects?

    a) Book books[];
        books = new Book[ numberElements ];

    b) Book books[];
        books = new Book()[ numberElements ];

    c) new Book() books[];
        books = new Book[ numberElements ];
    • a) Book books[];   
    •     books = new Book[ numberElements ];
  549. Which statement below initializes array items
    to contain 3 rows and 2 columns?

    a) int items[][] = { { 2, 4 }, { 6, 8 }, { 10, 12 } };

    b) int items[][] = { { 2, 6, 10 }, { 4,
    8, 12 } };

    c) int items[][] = { 2, 4 }, { 6, 8 }, {
    10, 12 };

    d) int items[][] = { 2, 6, 10 }, { 4, 8,
    12 };
    a) int items[][] = { { 2, 4 }, { 6, 8 }, { 10, 12 } };
  550. A well designed method;

    A) repeats code found in other methods
    B) contains thousands of lines of code
    C) performs a single, well-defined task
    D) performs multiple unrelated tasks
    C) performs a single, well-defined task
    (this multiple choice question has been scrambled)
  551. Which of the following sets of statements
    creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items?

    a) int items[][];
    items = new int[ 3 ][ ? ];
    items[ 0 ] = new int[ 1 ];
    items[ 1 ] = new int[ 4 ];
    items[ 2 ] = new int[ 2 ];

    b) int items[][];
    items = new int[ 3 ][ ];
    items[ 0 ] = new int[ 1 ];
    items[ 1 ] = new int[ 4 ];
    items[ 2 ] = new int[ 2 ];

    c) int items[][];
    items = new int[ ? ][ ? ];
    items[ 0 ] = new int[ 1 ];
    items[ 1 ] = new int[ 4 ];
    items[ 2 ] = new int[ 2 ];

    d) int items[][];
    items[ 0 ] = new int[ 1 ];
    items[ 1 ] = new int[ 4 ];
    items[ 2 ] = new int[ 2 ];
    • b) int items[][];
    • items = new int[ 3 ][ ];
    • items[ 0 ] = new int[ 1 ];
    • items[ 1 ] = new int[ 4 ];
    • items[ 2 ] = new int[ 2 ];
  552. When an argument is passed by reference:

    a) a copy of the argument’s value is passed to the called method.

    b) changes to the argument do not affect the original variable’s value in
    the caller.

    c) the called method can access the argument’s value in the caller directly
    and modify that data.

    d) the original value is removed from memory.
    c) the called method can access the argument’s value in the caller directlyand modify that data.
  553. In array items, which expression below retrieve the value at row 3 and column 5?

    A) items[ 3[ 4 ] ]
    B) items[ 3, 4 ]
    C) items[ 3 ][ 4 ]
    D) items[ 3 ].[ 4 ]
    C) items[ 3 ][ 4 ]
    (this multiple choice question has been scrambled)
  554. Attributes of a class are also known as;

    A) fields
    B) local variables
    C) constructors
    D) classes
    A) fields
    (this multiple choice question has been scrambled)
  555. What it the output of the following program?

    public class TestApp {

         public static void main(String[] args) {

              int items[] = {0, 2, 4, 6, 8};

              outputArray(items );

              changeArray(items, items[ 2 ] );

              outputArray(items );      

         }
    // end method main

         public static void outputArray( int passedArray[] )

         {

              for
    ( int item : passedArray )

                  System.out.printf("%d   ", item);
                  System.out.println();

         }
    // end method outputArray

         public static void changeArray( int passedArray[], int value )

         {

              passedArray[
    value ] = 12;

              value
    = 5;

         }
    // end method changeArray

    } // end class TestApp
    • 0   2   4  6   8
    • 0   2   4  6   12
  556. Which of the following should usually be private?

    A. Constructors.
    B. Variables (or fields).
    C. Methods.
    d. All of the above.
    B. Variables (or fields).
    (this multiple choice question has been scrambled)
  557. Which of the following statements is true?

    A.The private members of a class are directly accessible to the client of a class.
    B.Methods and instance variables can both be either public or private.
    C.Information hiding is achieved by restricting access to class members via keyword public.
    d.None of the above is true.
    B.Methods and instance variables can both be either public or private.
    (this multiple choice question has been scrambled)
  558. What type of methods allow a client of a class to assign values to a private instance variable?

    A) assign methods
    B) replace methods
    C) set methods
    D) get methods
    C) set methods
    (this multiple choice question has been scrambled)
  559. When should a program explicitly use the this
    reference?

    A. Accessing a field that is shadowed by a local variable.
    B. Accessing a private variable.
    C. Accessing a local variable.
    D. Accessing a public variable.
    C. Accessing a local variable.
    (this multiple choice question has been scrambled)
  560. Having a this reference allows:

    a. A method to refer explicitly to the instance variables and other methods of the object on which the method was called.
    b. A method to refer implicitly to the instance variables and other methods of the object on which the method was called.
    c. An object to reference itself.
    d. All of the above.
    d. All of the above.
  561. A constructor cannot:

    A. Initialize variables to their defaults.
    B. Be overloaded.
    C. Have the same name as the class.
    D. Specify return types or return values.
    D. Specify return types or return values.
    (this multiple choice question has been scrambled)
  562. Constructors:

    A. Initialize instance variables.
    B. When overloaded, can have identical argument lists.
    C. When overloaded, are selected by number and types of parameters.
    D. a and c.
    D. a and c.
    (this multiple choice question has been scrambled)
  563. Declaring main as _____________ allows the JVM to invoke main without creating an instance of the class.

    A) final
    B) void
    C) static
    D) public
    C) static
    (this multiple choice question has been scrambled)
  564. When implementing a method, use the class’s set and get methods to access the class’s ________ data.

    A. protected.
    B. public.
    C. private.
    d. All of the above.
    C. private.
    (this multiple choice question has been scrambled)
  565. Which statement is false?

    A. A constructor can be called with no arguments only if the class does not have any constructors or if the class has a public no-argument constructor.
    B. If a class has constructors, but none of the public constructors are no-argument constructors, and a program attempts to call a no-argument constructor to initialize an object of he class, a compilation error occurs.
    C.The compiler always creates a default constructor for a class.
    D. Java allows other methods of the class besides its constructors to have the same name as the class and to specify return types.
    C.The compiler always creates a default constructor for a class.
    (this multiple choice question has been scrambled)
  566. Not using set and get methods is:

    A. Not good program design.
    B. A syntax error.
    C. A logic error.
    d. None of the above.
    A. Not good program design.
    (this multiple choice question has been scrambled)
  567. Using public set methods provides data integrity if:

    A. Both b and c.
    B. The methods perform validity checking.
    C. The instance variables are public.
    D. The instance variables are private.
    A. Both b and c.
    (this multiple choice question has been scrambled)
  568. Composition is sometimes referred to as a(n)
    ________.

    A. is-a relationship.
    B. one-to-many relationship.
    C. have-a relationship.
    D. has-a relationship.
    D. has-a relationship.
    (this multiple choice question has been scrambled)
  569. Static class variables:

    A. Are private.
    B. Are public.
    C. Are shared by all objects of a class.
    D. Are final.
    C. Are shared by all objects of a class.
    (this multiple choice question has been scrambled)
  570. Which of the following is not true?

    a) A static method must be used to access private static instance variables.
    b) A static method has no this reference.
    c) A static method can be accessed even when no objects of its class have been instantiated.
    d) A static method can call instance methods directly.
    d. A static method can call instance methods directly.
  571. Instance variables declared final do not or cannot:

    A. Cause syntax errors if used as a left-hand value.
    B. Be initialized.
    C. Be modified.
    D.Use the principle of least privilege.
    C. Be modified.
    (this multiple choice question has been scrambled)
  572. The term information hiding refers to:

    A) public methods.
    B) The process of releasing an object for garbage collection.
    C) Hiding implementation details from clients of a class.
    D) Accessing static class members.
    C) Hiding implementation details from clients of a class.
    (this multiple choice question has been scrambled)
  573. A package is:

    a) A directory structure used to organize classes and interfaces.
    b) A mechanism for software reuse.
    c) A group of related classes and interfaces.
    d) All of the above.
    d) All of the above.
  574. The import declaration import *; ________.

    A) causes a compilation error.
    B) imports the classes in package java.lang.
    C) imports all classes in the library.
    D) imports the default classes in the library.
    A) causes a compilation error.
    (this multiple choice question has been scrambled)
  575. Write a program in which you have a class called Balloon. This class is for drawing some balloons on a given environment. It will have x,y,w,h  and color variables and a draw method. Another class of type JFrame will have a Balon inside a JPanel, and a button. When you click the button the balloon will expand 10 pixel and change its color to another random color.
    • public class Balloon {
    •                int x,y,w,h;
    •                Color c;
    •   public Balloon(int
    •          x1,int y1,int w1,int h1, Color c1) {
    •          x=x1;    
    •          y=y1;    
    •          w=w1;    
    •          h=h1;
    •          c=c1;
    •   }

    •   public void draw(Graphics g){
    •                 g.setColor(c);  
    •                 g.drawRect(x,y,w,h);  
    •                 g.drawOval(x,y,w,h);    

    •                 g.fillOval(x,y,w,h);
    •   }

    }


    • import javax.swing.*;
    • import java.awt.*;
    • import java.awt.event.*;
    • import java.util.*;

    • public class mm extends JFrame
    •            implements   ActionListener{
    •                     Balloon b;
    •                     JButton jb;
    •                     JPanel jp;
    •                     Random rn;
    •              public mm(){
    •                    jp=new JPanel();
    •                    jb=new JButton("ok");
    •                    rn=new Random();
    •                   Container c =  
    •                           this.getContentPane();
    •          c.setLayout(new GridLayout(1,2));
    •                    jb.addActionListener(this);
    •                    c.add(jb);
    •         b=new Balloon(100,100,100,100,new Color(255,0,0));

    •         c.add(jp);
    •         jp.setBackground(Color.WHITE);
    •         setSize(500,500);
    •         setVisible(true);

    •         // new
    • Timer(1000,this).start();
    • }

    • public void paint(Graphics g){
    •             super.paint(g);
    •             int re=rn.nextInt(256);
    •             int gr=rn.nextInt(256);
    •             int bl=rn.nextInt(256);
    •         b.c=new Color(re,gr,bl);
    •         b.draw(jp.getGraphics());
    • }

    • public void actionPerformed(ActionEvent e){
    •         b.w=b.w+20;
    •         b.h=b.h+20;
    •         repaint();
    • }

    •  public static void main(String[] args) {
    •         mm f=new mm();
    • f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    •  }
    • }
  576. An argument type followed by a(n)____________________ in a method's parameter list indicates that the method receives a variable number of arguments of that particular type.

    A. square brackets ([]).
    B. varargs keyword.
    C. ellipsis (...).
    d. All of the above are acceptable to indicate a variable number of arguments.
    C. ellipsis (...).
    (this multiple choice question has been scrambled)
  577. Which command below runs TestProgram, and passes in the values files.txt and 3?

    A. java TestProgram (the arguments files.txt and 3 were passed in when the application was compiled).
    B. java TestProgram "files.txt", "3".
    C. java TestProgram files.txt, 3.
    D. java TestProgram files.txt 3.
    D. java TestProgram files.txt 3.
    (this multiple choice question has been scrambled)
  578. Which method call converts the value in variable stringVariable to an integer?

    A. Convert.toInt( stringVariable ).
    B. Integer.toInt( stringVariable ).
    C. Convert.parseInt( stringVariable ).
    D. Integer.parseInt( stringVariable ).
    D. Integer.parseInt( stringVariable ).
    (this multiple choice question has been scrambled)
  579. Class Arrays methods sort, binarySearch, equals and fill are overloaded for primitive-type arrays and Object arrays. In addition, methods __________ and __________ are overloaded with generic versions.

    A. binarySearch, equals.
    B. sort, fill.
    C. binarySearch, fill.
    D. sort, binarySearch.
    A. binarySearch, equals.
    (this multiple choice question has been scrambled)
  580. Class Arrays provides method __________ for comparing arrays.

    A. equals.
    B. compare.
    C. equal.
    D. compares.
    A. equals.
    (this multiple choice question has been scrambled)
  581. Class ________ represents a dynamically resizable array-like data structure.

    A. Arrays.
    B. ArrayList.
    C. Array.
    d. None of the above.
    B. ArrayList.
    (this multiple choice question has been scrambled)
  582. Which of the following is false?

    A. The size of an ArrayList can be determined via its size method.
    B. You can get an item from a specified index in an ArrayList with its get method.
    C. The size of an ArrayList can be determined via its length instance variable.
    D. You can add a new item to the end of an ArrayList with its add method.
    C. The size of an ArrayList can be determined via its length instance variable.
    (this multiple choice question has been scrambled)
  583. Which method sets the background color of a JPanel?

    A. setBack.
    B. setColor.
    C. setBackground.
    D. setBackgroundColor.
    C. setBackground.
    (this multiple choice question has been scrambled)
  584. Which of the following statements about an arc is false?

    A. An arc is a section of an oval.
    B. The fillArc method draws an oval, with the section that is an arc filled in.
    C. The sweep is the amount of arc to cover.
    D. Method drawArc draws the edges of an arc.
    B. The fillArc method draws an oval, with the section that is an arc filled in.
    (this multiple choice question has been scrambled)
  585. Arrays are: 

    A. variable-length entities.
    B. used to draw a sequence of lines, or "rays."
    C. fixed-length entities.
    D. data structures that contain up to 10 related data items.
    C. fixed-length entities.
    (this multiple choice question has been scrambled)
  586. Which of the following statements about arrays are true?

    A. The length of an array c is determined by the expression c.length();.
    B. Elements are located by index or subscript.
    C. The zeroth element of array c is specified by c[ 0 ].
    D. An array is a group of variables containing values that all have the same type.

    a. A, C, D.
    b. A, B, D.
    c. C, D.
    d. A, B, C, D.
    B. A, B, D.
    (this multiple choice question has been scrambled)
  587. Consider the array:

    s[ 0 ] = 7
    s[ 1 ] = 0
    s[ 2 ] = -12
    s[ 3 ] = 9
    s[ 4 ] = 10
    s[ 5 ] = 3
    s[ 6 ] = 6

    The value of s[ s[ 6 ] - s[ 5 ] ] is:

    A. 9.
    B. 0.
    C. 3.
    D. 0.
    A. 9.
    (this multiple choice question has been scrambled)
  588. A programmer must do the following before using an array:

    A. create then reference the array.
    B. create then declare the array.
    C. declare then reference the array.
    D. declare then create the array.
    D. declare then create the array.
    (this multiple choice question has been scrambled)
  589. Consider the code segment below. Which of the following statements is false?

    int[] g; g = new int[ 23 ];

    A. g is a reference to an array of integers.
    B. The second statement creates the array.
    C. The value of g[ 3 ] is -1.
    D. The first statement declares an array reference.
    C. The value of g[ 3 ] is -1.
    (this multiple choice question has been scrambled)
  590. Which of the following statements about creating arrays and initializing their elements is false?

    A. When an array is created, the number of elements must be placed in square brackets following the type of element being stored.
    B. The new keyword should be used to create an array.
    C. The elements of an array of integers have a value of null before they are initialized.
    D. A for loop is commonly used to set the values of the elements of an array.
    C. The elements of an array of integers have a value of null before they are initialized.
    (this multiple choice question has been scrambled)
  591. What do the following statements do?

         double[] array;
         array = new double[ 14 ];

    A. Create a double array containing 13 elements.
    B. Declare but do not create a double array.
    C. Create a double array containing 14 elements.
    D. Create a double array containing 15 elements.
    C. Create a double array containing 14 elements.
    (this multiple choice question has been scrambled)
  592. Which of the following initializer lists would correctly set the elements of array n?

    A. int n[ 5 ] = { 1; 2; 3; 4; 5 };.
    B. array n[ int ] = { 1, 2, 3, 4, 5 };.
    C. int[] n = { 1, 2, 3, 4, 5 };.
    D. int n = new int( 1, 2, 3, 4, 5 );.
    C. int[] n = { 1, 2, 3, 4, 5 };.
    (this multiple choice question has been scrambled)
  593. Constant variables also are called ________________.

    A. finals.
    B. write-only variables.
    C. named constants.
    d. All of the above.
    C. named constants.
    (this multiple choice question has been scrambled)
  594. Which of the following will not produce a compiler error?

    A. Changing the value of a constant after it is declared.
    B. Using a final variable before it is initialized.
    C. Changing the value at a given index of an array after it is created.
    d. All of the above will produce compiler errors.
    C. Changing the value at a given index of an array after it is created.
    (this multiple choice question has been scrambled)
  595. Consider the class below:

    public class Test { public static void main( String[] args )
    {
        int[] a = { 99, 22, 11, 3, 11, 55, 44, 88, 2, -3 };
        int result = 0;

            for ( int i = 0; i < a.length; i++ )
                {
                     if ( a[ i ] > 30 ) result += a[ i ]; } // end for

    System.out.printf( "Result is: %dn", result ); } // end main
    } // end class Test

    The output of this Java program will be:

    A. Result is: 332.
    B. Result is: 154.
    C. Result is: 286.
    D. Result is: 280.
    C. Result is: 286.
    (this multiple choice question has been scrambled)
  596. Which flag in a format specifier indicates that values with fewer digits than the field width should begin with a leading 0?

    A. l.
    B. 0.
    C. p.
    D. w.
    B. 0.
    (this multiple choice question has been scrambled)
  597. Invalid possibilities for array indices include _______________. 

    A. Zero.
    B. Negative integers.
    C. Positive integers.
    d. None of the above.
    B. Negative integers.
    (this multiple choice question has been scrambled)
  598. Which of the following statements is false?

    A. The catch block contains the code that might throw an exception, and the try block contains the code that handles the exception if one occurs. 
    B. Inside the catch block, you can use the parameter's identifier to interact with a caught exception object.
    C. An exception indicates a problem that occurs while a program executes. 
    D. Exception handling enables you to create fault-tolerant programs that can resolve (or handle) exceptions—in many cases, this allows a program to continue executing as if no problems were encountered. 
    A. The catch block contains the code that might throw an exception, and the try block contains the code that handles the exception if one occurs.
    (this multiple choice question has been scrambled)
  599. Which of the following tasks cannot be performed using an enhanced for loop?

    A. Comparing the elements in an array to a specific value.
    B. Incrementing the value stored in each element of the array.
    C. Calculating the product of all the values in an array.
    D. Displaying all even element values in an array.
    B. Incrementing the value stored in each element of the array.
    (this multiple choice question has been scrambled)
  600. Which statement correctly passes the array items to method takeArray? Array items contains 10 elements.

    A. takeArray( items ).
    B. takeArray( items[ 9 ] ).
    C. takeArray( items[] ).
    D. Arrays cannot be passed to methods—each item must be sent to the method separately.
    A. takeArray( items ).
    (this multiple choice question has been scrambled)
  601. Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray is called with the method call changeArray( items, items[ 2 ] ), what values are stored in items after the method has finished executing?

    public static void changeArray( int[] passedArray, int value )
    { passedArray[ value ] = 12;
                             value = 5; } // end method changeArray

    A. 0, 2, 12, 6, 8.
    B. 0, 2, 4, 6, 12.
    C. 0, 2, 5, 6, 12.
    D. 0, 2, 4, 6, 5.
    B. 0, 2, 4, 6, 12.
    (this multiple choice question has been scrambled)
  602. When an argument is passed by reference:

    A. the original value is removed from memory.
    B. changes to the argument do not affect the original variable's value in the caller.
    C. a copy of the argument's value is passed to the called method.
    D. the called method can access the argument's value in the caller directly and modify that data.
    D. the called method can access the argument's value in the caller directly and modify that data.
    (this multiple choice question has been scrambled)
  603. What kind of application tests a class by creating an object of that class and calling the class's methods?

    A. Tester.
    B. Test harness.
    C. Debugger.
    D. Pseudo application.
    B. Test harness.
    (this multiple choice question has been scrambled)
  604. In Java, multidimensional arrays:

    a. are not directly supported.
    b. are implemented as arrays of arrays.
    c. are often used to represent tables of values.
    d. All of the above.
    d. All of the above.
  605. An array with m rows and n columns is not:

    A. An m-by-n array.
    B. A dual-transcripted array.
    C. A two-dimensional array.
    D. An n-by-m array.

    a. A and C.
    b. A and D.
    c. B and D.
    d. B and C.
    C. B and D.
    (this multiple choice question has been scrambled)
  606. Which statement below initializes array items to contain 3 rows and 2 columns?

    A. int[][] items = { 2, 4 }, { 6, 8 }, { 10, 12 };.
    B. int[][] items = { { 2, 4 }, { 6, 8 }, { 10, 12 } };.
    C. int[][] items = { 2, 6, 10 }, { 4, 8, 12 };.
    D. int[][] items = { { 2, 6, 10 }, { 4, 8, 12 } };.
    B. int[][] items = { { 2, 4 }, { 6, 8 }, { 10, 12 } };.
    (this multiple choice question has been scrambled)
  607. Superclass methods with this level of access cannot be called from subclasses.

    A. package.
    B. protected.
    C. public.
    D. private.
    D. private.
    (this multiple choice question has been scrambled)
  608. Private fields of a superclass can be accessed in a subclass;

    A. by calling public or protected methods declared in the superclass.
    B. by calling private methods declared in the superclass.
    C. directly.
    d. All of the above.
    A. by calling public or protected methods declared in the superclass.
    (this multiple choice question has been scrambled)
  609. For which of the following would polymorphism not provide a clean solution?

    a. A billing program where there is a variety of client types that are billed with different fee structures.
    b. A maintenance log program where data for a variety of types of machines is collected and maintenance schedules
    are produced for each machine based on the data collected.
    c. A program to compute a 5% savings account interest for a variety of clients.
    d. An IRS program that maintains information on a variety of taxpayers and determines who to audit based on
    criteria for classes of taxpayers.
    c. A program to compute a 5% savings account interest for a variety of clients.

    Because there is only one kind of calculation then there is no need for polymorphism.
  610. A(n) ______ class cannot be instantiated.

    A. abstract.
    B. polymorphic.
    C. final.
    D. concrete.
    A. abstract.
    (this multiple choice question has been scrambled)
  611. Consider classes A, B and C, where A is an abstract superclass, B is a concrete class that inherits from A, and C  is a concrete class that inherits from B. Class A declares abstract method originalMethod, implemented in class
    Which of the following statements is true of class C?

    a. Method originalMethod cannot be overridden in class C—once it has been implemented in concrete class B,
    it is implicitly final.
    b. Method originalMethod must be overridden in class C, or a syntax error will occur.
    c. If method originalMethod is not overridden in class C but is called by an object of class C, an error occurs.
    d. None of the above.
    d. None of the above.
  612. An interface may contain:

    A. private static data and public final methods.
    B. private static data and public abstract methods.
    C. only public abstract methods.
    D. public static final data and public abstract methods.
    D. public static final data and public abstract methods.
    (this multiple choice question has been scrambled)
  613. Which of the following is not true of heavyweight components?

    A. The functionality may vary across platforms.
    B. AWT components are not heavyweight components.
    C. The look-and-feel may vary across platforms.
    D. Several Swing components are heavyweight components.
    B. AWT components are not heavyweight components.
    (this multiple choice question has been scrambled)
  614. Which of the following statements makes the text in a JTextField uneditable?

    A. textField.setEditable( false );
    B. textField.setUneditable( true );
    C. textField.setEditable( true );
    D. textField.setUneditable( false );
    A. textField.setEditable( false );
    (this multiple choice question has been scrambled)
  615. The GUI event with which the user interacts is the;

    A. event source.
    B. event raiser.
    C. event effector.
    D. event container.
    A. event source.
    (this multiple choice question has been scrambled)
  616. Which method determines if a JCheckBox is selected?

    A. getSelected.
    B. isSelected.
    C. selected.
    d. None of the above.
    B. isSelected.
    (this multiple choice question has been scrambled)
  617. Which of the following objects cannot trap mouse events?

    A. JComponent.
    B. JButton.
    C. ButtonGroup.
    D. JTextField.
    C. ButtonGroup.
    (this multiple choice question has been scrambled)
  618. The Shift key is a(n) ______ key.

    A. output.
    B. action.
    C. modifier.
    d. None of the above.
    C. modifier.
    (this multiple choice question has been scrambled)
  619. The class GridLayout constructs ______ to hold components.

    A. a horizontal grid with one row.
    B. a vertical grid with one column.
    C. a square grid with the same number of rows as columns.
    D. a grid with multiple rows and columns.
    D. a grid with multiple rows and columns.
    (this multiple choice question has been scrambled)
  620. A String constructor cannot be passed variables of type:

    A. char arrays.
    B. byte arrays.
    C. Strings.
    D. int arrays.
    D. int arrays.
    (this multiple choice question has been scrambled)
  621. The statement;

    s1.equalsIgnoreCase( s4 )

    is equivalent to which of the following?

    A. s1.regionMatches( true, 0, s4, 0, s4.length() );
    B. s1.regionMatches( true, s4, 0, s4.length );
    C. s1.regionMatches( 0, s4, 0, s4.length );
    D. s1.regionMatches( 0, s4, 0, s4.length() );
    A. s1.regionMatches( true, 0, s4, 0, s4.length() );
    (this multiple choice question has been scrambled)
  622. Given the following declarations:

    StringBuilder buf;
    StringBuilder buf2 = new StringBuilder();
    String c = new String( "test" );

    Which of the following is not a valid StringBuilder constructor?

    A. buf = new StringBuilder( buf2, 32 );
    B. buf = new StringBuilder();
    C. buf = new StringBuilder( c );
    D. buf = new StringBuilder( 32 );
    A. buf = new StringBuilder( buf2, 32 );
    (this multiple choice question has been scrambled)
  623. Consider the Java segment:

    String line1 = new String( "c = 1 + 2 + 3" ) ;
    StringTokenizer tok = new StringTokenizer( line1, delimArg );

    For the String line1 to have 4 tokens, delimArg should be;

    A. String delimArg = "c+";
    B. String delimArg = " ";
    C. String delimArg = "123"
    D. String delimArg = "+=";
    D. String delimArg = "+=";
    (this multiple choice question has been scrambled)
  624. Intermixing program and error-handling logic;

    A. can degrade a program’s performance, because the program must perform (potentially frequent) tests to determine whether a task executed correctly and the next task can be performed.
    B. increases a program’s performance, because the program does not need to perform tests to determine whether a task executed correctly and the next task can be performed.
    C. should be used in place of exception handling where possible.
    d. None of the above.
    A. can degrade a program’s performance, because the program must perform (potentially frequent) tests to determine whether a task executed correctly and the next task can be performed.
    (this multiple choice question has been scrambled)
  625. All exception classes inherit, either directly or indirectly, from;

    A. class RuntimeException.
    B. class Error.
    C. class Throwable.
    d. None of the above.
    C. class Throwable.
    (this multiple choice question has been scrambled)
  626. Which of the following statements is false?

    A. A record is typically composed of several fields.
    B. The term “bit” is short for “byte digit.”
    C. The smallest data item a computer can assume is the value 0 or the value 1.
    D. Java uses the Unicode character set.
    B. The term “bit” is short for “byte digit.”
    (this multiple choice question has been scrambled)
  627. When all the contents of a file are truncated, this means that;

    A. All the data in the file is discarded.
    B. the file is deleted.
    C. the data in the file is saved to a backup file.
    D. a FileNotFoundException occurs.
    A. All the data in the file is discarded.
    (this multiple choice question has been scrambled)
  628. Which of the following classes enable input and output of entire objects to or from a file?

    A. Scanner
    B. Formatter
    C. SerializedInputStream
    D. ObjectInputStream
    E. ObjectOutputStream
    F. SerializedOutputStream

    a. A and B.
    b. C and D.
    c. C, D, E, F.
    d. E and F.
    F. C and D.
    (this multiple choice question has been scrambled)
  629. Given the following variables;

    char c = 'c';
    int i = 10;
    double d = 10;
    long l = 1;
    String s = "Hello";

    Which of the following will compile without error?

    1) c=c+i;
    2) s+=i;
    3) i+=s;
    4) c+=s;
    2) s+=i;

    Only a String acts as if the + operator were overloaded
  630. class C {
       public static void main(String[] args) {
                           int i1=1;
                   switch(i1){
                    case 1: System.out.println("one");
                    case 2: System.out.println("two");
                  case 3: System.out.println("three");
    }}}

    What is the result of attempting to compile and run the program?

    1. prints one two three
    2. prints one
    3. compile time error
    4. Runtime exceptionf
    5. None of the above
    1. prints one two three

    There is no break statement in case 1 so it causes the lower case statements to execute regardless of their values
  631. class C{
                int i;
              public static void main (String[] args) {
                 int i; //1
                 private int a = 1; //2
                 protected int b = 1; //3
                 public int c = 1; //4
             System.out.println(a+b+c); //5
    }}

    1. compiletime error at lines 1,2,3,4,5
    2. compiletime error at lines 2,3,4,5
    3. compiletime error at lines 2,3,4
    4. prints 3
    5. None of the above
    2. compiletime error at lines 2,3,4,5

    The access modifiers public, protected and private, can not be applied to variables declared inside methods.
  632. What will happen when you attempt to compile and run this code?

    abstract class Base{
         abstract public void myfunc();
         public void another(){  
         System.out.println("Another method"); }}

    public class Abs extends Base{
          public static void main(String argv[]){
                 Abs a = new Abs();
                 a.amethod();
                 }
                 public void myfunc(){  
                    System.out.println("My Func");
                       }
                 public void amethod(){
                    myfunc();
    }}

    1) The code will compile and run, printing out the words "My Func"
    2) The compiler will complain that the Base class has non abstract methods
    3) The code will compile but complain at run time that the Base class has non abstract methods
    4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it
    1) The code will compile and run, printing out the words "My Func"

    A class that contains an abstract method must be declared abstract itself, but may contain non abstract methods.
  633. What will happen when you attempt to compile and run this code?

    public class MyMain{
         public static void main(String argv){  
           System.out.println("Hello cruel world"); }}

    1) The compiler will complain that main is a reserved word and cannot be used for a class
    2) The code will compile and when run will print out "Hello cruel world"
    3) The code will compile but will complain at run time that no constructor is defined
    4) The code will compile but will complain at run time that main is not correctly defined
    4) The code will compile but will complain at run time that main is not correctly defined

    In this example the parameter is a string not a string array as needed for the correct main method
  634. Which of the following are Java modifiers?

    1) public
    2) private
    3) friendly
    4) transient
    5) vagrant
    1) public, 2) private, 4) transient

    The keyword transient is easy to forget as is not frequently used. Although a method may be considered to be friendly like in C++ it is not a Java keyword.
  635. What will happen when you attempt to compile and run this code?

    class Base{
            abstract public void myfunc();
              public void another(){    
          System.out.println("Another method"); }}

          public class Abs extends Base{
                 public static void main(String argv[])
                {
                 Abs a = new Abs();
                 a.amethod();
                 }

           public void myfunc(){          
               System.out.println("My func"); }

           public void amethod(){
                  myfunc();
    }}

    1) The code will compile and run, printing out the words "My Func"
    2) The compiler will complain that the Base class is not declared as abstract.
    3) The code will compile but complain at run time that the Base class has non abstract methods
    4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it
    2) The compiler will complain that the Base class is not declared as abstract.

    If a class contains abstract methods it must itself be declared as abstract
  636. Why might you define a method as native? (More than one answer maybe true).

    1) To get to access hardware that Java does not know about
    2) To define a new data type such as an unsigned integer
    3) To write optimised code for performance in a language such as C/C++
    4) To overcome the limitation of the private scope of a method
    • 1) To get to access hardware that Java does not know about
    • 3) To write optimised code for performance in a language such as C/C++
  637. What will happen when you attempt to compile and run this code?

            class Base{
    public final void amethod(){
            System.out.println("amethod");
    }}

    public class Fin extends Base{
          public static void main(String argv[]){
                    Base b = new Base();
                    b.amethod();
    }}

    1) Compile time error indicating that a class with any final methods must be declared final itself
    2) Compile time error indicating that you cannot inherit from a class with final methods
    3) Run time error indicating that Base is not defined as final
    4) Success in compilation and output of "amethod" at run time.
    4) Success in compilation and output of "amethod" at run time.

    A final method cannot be ovverriden in a sub class, but apart from that it does not cause any other restrictions.
  638. What will happen when you attempt to compile and run this code?

    public class Mod{
    public static void main(String argv[]){
    }
            public static native void amethod();
    }

    1) Error at compilation: native method cannot be static
    2) Error at compilation native method must return value
    3) Compilation but error at run time unless you have made code containing native amethod available
    4) Compilation and execution without error
    4) Compilation and execution without error

    It would cause a run time error if you had a call to amethod though.
  639. What will happen when you attempt to compile and run this code?

    private class Base{}
    public class Vis{
                    transient int iVal;
            public static void main(String elephant[]){
    }}

    1) Compile time error: Base cannot be private
    2) Compile time error indicating that an integer cannot be transient
    3) Compile time error transient not a data type
    4) Compile time error malformed main method
    1)Compile time error: Base cannot be private

    A top level (non nested) class cannot be private.
  640. What happens when you attempt to compile and run these two files in the same directory?

    //File P1.java
    package MyPackage;
    class P1{
    void afancymethod(){  
          System.out.println("What a fancy method");
    }}

    //File P2.java
    public class P2 extends P1{
      public static void main(String argv[]){
                P2 p2 = new P2();
                p2.afancymethod();
    }}

    1) Both compile and P2 outputs "What a fancy method" when run
    2) Neither will compile
    3) Both compile but P2 has an error at run time
    4) P1 compiles cleanly but P2 has an error at compile time
    4) P1 compiles cleanly but P2 has an error at compile time

    The package statement in P1.java is the equivalent of placing the file in a different directory to the file P2.java and thus when the compiler tries to compile P2 an error occurs indicating that superclass P1 cannot be found.
  641. You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.?

    public class MyAr{
    public static void main(String argv[]){
              int[] i = new int[5];
              System.out.println(i[5]);
    }}

    1) An error at compile time
    2) An error at run time
    3) The value 0 will be output
    4) The string "null" will be output
    2) An error at run time

    This code will compile, but at run-time you will get an ArrayIndexOutOfBounds exception. This becuase counting in Java starts from 0 and so the 5th element of this array would be i[4].

    Remember that arrays will always be initialized to default values wherever they are created.
  642. You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?

    1)myarray.length();
    2)myarray.length;
    3)myarray.size
    4)myarray.size();
    2)myarray.length;

    The String class has a length() method to return the number of characters. I have sometimes become confused between the two.
  643. What best describes the appearance of an application with the following code?

    import java.awt.*;
    public class FlowAp extends Frame{
    public static void main(String argv[]){
          FlowAp fa=new FlowAp();  
          fa.setSize(400,300);
          fa.setVisible(true);
    }

    FlowAp(){
          add(new Button("One"));
          add(new Button("Two"));
          add(new Button("Three"));
          add(new Button("Four"));
    }//End of constructor
    }//End of Application

    1) A Frame with buttons marked One to Four placed on each edge.
    2) A Frame with buutons marked One to four running from the top to bottom
    3) A Frame with one large button marked Four in the Centre
    4) An Error at run time indicating you have not set a LayoutManager
    3) A Frame with one large button marked Four in the Centre

    The default layout manager for a Frame is the BorderLayout manager. This Layout manager defaults to placing components in the centre if no constraint is passed with the call to the add method.
  644. How do you indicate where a component will be positioned using Flowlayout?

    1) North, South,East,West
    2) Assign a row/column grid reference
    3) Pass a X/Y percentage parameter to the add method
    4) Do nothing, the FlowLayout will position the component
    4) Do nothing, the FlowLayout will position the component
  645. How do you change the current layout manager for a container?

    1) Use the setLayout method
    2) Once created you cannot change the current layout manager of a component
    3) Use the setLayoutManager method
    4) Use the updateLayout method
    1) Use the setLayout method
  646. Which of the following are fields of the GridBagConstraints class?

    1) ipadx
    2) fill
    3) insets
    4) width
    1) ipadx, 2) fill, 3) insets
  647. What most closely matches the appearance when this code runs?

    import java.awt.*;
    public class CompLay extends Frame{
    public static void main(String argv[]){
          CompLay cl = new CompLay(); }

    CompLay(){
               Panel p = new Panel();      
               p.setBackground(Color.pink);
               p.add(new Button("One"));
               p.add(new Button("Two"));
               p.add(new Button("Three"));
               add("South",p);
               setLayout(new FlowLayout());
               setSize(300,300);
               setVisible(true);
    }}

    1) The buttons will run from left to right along the bottom of the Frame
    2) The buttons will run from left to right along the top of the frame
    3) The buttons will not be displayed
    4) Only button three will show occupying all of the frame
    2) The buttons will run from left to right along the top of the frame

    The call to the setLayout(new FlowLayout()) resets the Layout manager for the entire frame and so the buttons end up at the top rather than the bottom.
  648. Which statements are correct about the anchor field? (More than one answer may apply).

    1) It is a field of the GridBagLayout manager for controlling component placement
    2) It is a field of the GridBagConstraints class for controlling component placement
    3) A valid setting for the anchor field is GridBagConstraints.NORTH
    4) The anchor field controls the height of components added to a container
    • 2) It is a field of the GridBagConstraints class for controlling component placement
    • 3) A valid settting for the anchor field is GridBagconstraints.NORTH
  649. What will happen when you attempt to compile and run the following code?

    public class Bground extends Thread{
    public static void main(String argv[]){  
           Bground b = new Bground();
           b.run();
           }

    public void start(){
           for (int i = 0; i <10; i++){  
               System.out.println("Value of i = " + i); } }}

    1) A compile time error indicating that no run method is defined for the Thread class
    2) A run time error indicating that no run method is defined for the Thread class
    3) Clean compile and at run time the values 0 to 9 are printed out
    4) Clean compile but no output at runtime
    4) Clean compile but no output at runtime

    This is a bit of a sneaky one as I have swapped around the names of the methods you need to define and call when running a thread.

    If the for loop were defined in a method called public void run() and the call in the main method had been to b.start() The list of values from 0 to 9 would have been output.
  650. True/False:  When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class.
    False

    You can re-use the same instance of the GridBagConstraints when added successive components.
  651. How does the set collection deal with duplicate elements?

    1) An exception is thrown if you attempt to add an element with a duplicate value
    2) The add method returns false if you attempt to add an element with a duplicate value
    3) A set may contain elements that return duplicate values from a call to the equals method
    4) Duplicate values will cause an error at compile time
    2) The add method returns false if you attempt to add an element with a duplicate value

    I find it a surprise that you do not get an exception.
  652. What can cause a thread to stop executing?

    1) The program exits via a call to System.exit(0);
    2) Another thread is given a higher priority
    3) A call to the thread's stop method.
    4) A call to the halt method of the Thread class?
    • 1) The program exits via a call to exit(0);
    • 2) The priority of another thread is increased
    • 3) A call to the stop method of the Thread class

    Note that this question asks what can cause a thread to stop executing, not what will cause a thread to stop executing.

    Java threads are somewhat platform dependent and you should be carefull when making assumptions about Thread priorities. On some platforms you may find that a Thread with higher priorities gets to "hog" the processor.

    You can read up on this in more detail at http://java.sun.com/docs/books/tutorial/essential/threads/priority.html
  653. For a class defined inside a method, what rule governs access to the variables of the enclosing method?

    1) The class can access any variable
    2) The class can only access static variables
    3) The class can only access transient variables
    4) The class can only access final variables
    4) The class can only access final variables
  654. Under what circumstances might you use the yield method of the Thread class?

    1) To call from the currently running thread to allow another thread of the same or higher priority to run
    2) To call on a waiting thread to allow it to run
    3) To allow a thread of higher priority to run
    4) To call from the currently running thread with a parameter designating which thread should be allowed to run
    1) To call from the currently running thread to allow another thread of the same or higher priority to run

    Option 3 looks plausible but there is no guarantee that the thread that grabs the cpu time will be of a higher priority. It will depend on the threading algorithm of the Java Virtual Machine and the underlying operating system
  655. What will happen when you attempt to compile and run the following code?

    public class Hope{
       public static void main(String argv[]){
                 Hope h = new Hope();
    }

        protected Hope(){
              for(int i =0; i <10; i ++){
                   System.out.println(i);
    } }}

    1) Compilation error: Constructors cannot be declared protected
    2) Run time error: Constructors cannot be declared protected
    3) Compilation and running with output 0 to 10
    4) Compilation and running with output 0 to 9
    4) Compilation and running with output 0 to 9
  656. What will happen when you attempt to compile and run the following code?

    public class MySwitch{
    public static void main(String argv[]){  
             MySwitch ms= new MySwitch();
             ms.amethod();
    }

    public void amethod(){
         int k=10;
                switch(k){
                default: //Put the default at the bottom, not here
                System.out.println("This is the default output");
                break;
         case 10: System.out.println("ten");
         case 20: System.out.println("twenty");
                 break;
    } }}

    1) None of these options
    2) Compile time error target of switch must be an integral type
    3) Compile and run with output "This is the default output"
    4) Compile and run with output of the single line "ten"
    1) None of these options

    Because of the lack of a break statement after the break 10; statement the actual output will be"ten" followed by "twenty"
  657. The design pattern known as "Model View Controller" (MVC), originated with what programming language?
    Smalltalk
  658. What part of the MVC design pattern is responsible for mapping user actions or events to queries or state changes of the model?
    Controller
  659. What part of the MVC design pattern is responsible for maintaining the current state of the system or application and comprises the underlying data representation of the system?
    Model
  660. What part of the MVC design pattern is responsible for what the user sees (what is presented to the user)?
    The View
  661. Which of the following is the correct syntax for suggesting that the JVM performs garbage collection?

    1) System.free();
    2) System.setGarbageCollection();
    3) System.out.gc();
    4) System.gc();
    4) System.gc();
  662. What will happen when you attempt to compile and run the following code?

    public class As{
             int i = 10;
             int j;
             char z= 1;
             boolean b;
        public static void main(String argv[]){
                 As a = new As();
                 a.amethod();
                 }
                 public void amethod(){
                     System.out.println(j);
                     System.out.println(b);
    }}

    1) Compilation succeeds and at run time an output of 0 and false
    2) Compilation succeeds and at run time an output of 0 and true
    3) Compile time error b is not initialised
    4) Compile time error z must be assigned a char value
    1) Compilation succeeds and at run time an output of 0 and false

    The default value for a boolean declared at class level is false, and integer is 0;
  663. What will happen when you attempt to compile and run the following code with the command line "hello there"?

    public class Arg{
    String[] MyArg;
        public static void main(String argv[]){
           MyArg=argv;
           }
         public void amethod(){
             System.out.println(argv[1]);
    }}

    1) Compile time error
    2) Compilation and output of "hello"
    3) Compilation and output of "there"
    4) None of the above
    1) Compile time error

    You will get an error saying something like "Cant make a static reference to a non static variable". Note that the main method is static. Even if main was not static the array argv is local to the main method and would thus not be visible within amethod.
  664. What will happen when you attempt to compile and run the following code?

    public class StrEq{
    public static void main(String argv[]){
         StrEq s = new StrEq();
         }

          private StrEq(){
                String s = "Marcus";
                String s2 = new String("Marcus");
                   if(s == s2){
            System.out.println("we have a match");          
                   }else{
            System.out.println("Not equal");
    } }}

    1) Compile time error caused by private constructor
    2) Output of "we have a match"
    3) Output of "Not equal"
    4) Compile time error by attempting to compare strings using ==
    3) Output of "Not equal"

    Despite the actual character strings matching, using the == operator will simply compare memory location. Because the one string was created with the new operator it will be in a different location in memory to the other string.
  665. What will happen when you attempt to compile and run the following code?

    import java.io.*;
    class Base{
       public void amethod()throws FileNotFoundException{}
    }

    public class ExcepDemo extends Base{
         public static void main(String argv[]){
                ExcepDemo e = new ExcepDemo();
    }

    public void amethod(){}
    protected ExcepDemo(){
             try{
                   DataInputStream din = new
                   DataInputStream(System.in);
                   System.out.println("Pausing");
                   din.readByte();
                   System.out.println("Continuing");
                   this.amethod();
          }catch(IOException ioe) {}
    }}

    1) Compile time error caused by protected constructor
    2) Compile time error caused by amethod not declaring Exception
    3) Runtime error caused by amethod not declaring Exception
    4) Compile and run with output of "Pausing" and "Continuing" after a key is hit
    4) Compile and run with output of "Pausing" and "Continuing" after a key is hit

    An overriden method in a sub class must not throw Exceptions not thrown in the base class. In the case of the method, amethod, it throws no exceptions and will thus compile without complain. There is no reason that a constructor cannot be protected.
  666. What will happen when you attempt to compile and run this program?

    public class Outer{
    public String name = "Outer";
    public static void main(String argv[]){
                 Inner i = new Inner();
                 i.showName();
    }//End of main

           private class Inner{
             String name =new String("Inner");
                   void showName(){
                        System.out.println(name);
                           }
                   }//End of Inner class
    }

    1) Compile and run with output of "Outer"
    2) Compile and run with output of "Inner"
    3) Compile time error because Inner is declared as private
    4) Compile time error because of the line creating the instance of Inner
    4) Compile time error because of the line creating the instance of Inner

    This looks like a question about inner classes but it is also a reference to the fact that the main method is static and thus you cannot directly access a non static method. The line causing the error could be fixed by changing it to say;

    Inner i = new Outer().new Inner();

    Then the code would compile and run producing the output "Inner".
  667. What will happen when you attempt to compile and run this code?

    //Demonstration of event handling
    import java.awt.*;
    import java.awt.event.*;
    public class MyWc extends Frame implements WindowListener{
    public static void main(String argv[]){
           MyWc mwc = new MyWc();
           }
           public void windowClosing(WindowEvent we){
            System.exit(0);
          }//End of windowClosing
           public void MyWc(){
                setSize(300,300);
                setVisible(true);
    }}//End of class

    1) Error at compile time
    2) Visible Frame created that that can be closed
    3) Compilation but no output at run time
    4) Error at compile time because of comment before import statements
    1) Error at compile time

    If you implement an interface you must create bodies for all methods in that interface. This code will produce an error saying that MyWc must be declared abstract because it does not define all of the methods in WindowListener. Option 4 is nonsense as comments can appear anywhere. Option 3 suggesting that it might compile but not produce output is meant to mislead on the basis that what looks like a constructor is actually an ordinary method as it has a return type.
  668. Which option most fully describes will happen when you attempt to compile and run the following code?

    public class MyAr{
          public static void main(String argv[]) {
                   MyAr m = new MyAr();
                   m.amethod();
          }
          public void amethod(){
                   static int i;
                   System.out.println(i);
    }}

    1) Compilation and output of the value 0
    2) Compile time error because i has not been initialized
    3) Compilation and output of null
    4) Compile time error
     
    4) Compile time error

    An error will be caused by attempting to define an integer as static within a method. The lifetime of a field within a method is the duration of the running of the method. A static field exists once only for the class. An approach like this does work with Visual Basic.
  669. Which of the following will compile correctly?

    1) short myshort = 99S;
    2) String name = 'Excellent tutorial Mr Green';
    3) char c = 17c;
    4) int z = 015;
    4) int z = 015;

    The letters c and s do not exist as literal indicators and a String must be enclosed with double quotes, not single as in this case.
  670. Which of the following are Java key words?

    1) double
    2) Switch
    3) then
    4) instanceof
    1) double, 4) instanceof

    Note the upper case S on switch means it is not a keyword and the word then is part of Visual Basic but not Java. Also, instanceof looks like a method but is actually a keyword,
  671. What will be output by the following line?

    System.out.println(Math.floor(-2.1));

    1) -2
    2) 2.0
    3) -3
    4) -3.0
    4) -3.0
  672. Given the following main method in a class called Cycle and a command line of;

    java Cycle one two

    what will be output?

    public static void main(String bicycle[]){
        System.out.println(bicycle[0]);
    }

    1) None of these options
    2) cycle
    3) one
    4) two
    3) one

    Command line parameters start from 0 and from the first parameter after the name of the compile (normally Java)
  673. Which of the following statements are true?

    1) At the root of the collection hierarchy is a class called Collection
    2) The collection interface contains a method called enumerator
    3) The interator method returns an instance of the Vector class
    4) The Set interface is designed for unique elements
    4) The Set is designed for unique elements.

    Collection is an interface, not a class. The Collection interface includes a method called iterator. This returns an instance of the Iterator class which has some similarities with Enumerators.The name set should give away the purpose of the Set interface as it is analogous to the Set concept in relational databases which implies uniquness.
  674. Which of the following statements are correct?

    1) If multiple listeners are added to a component only events for the last listener added will be processed
    2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
    3) Adding multiple listeners to a comnponent will cause a compile time error
    4) You may remove as well add listeners to a component.
    • 2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
    • 4) You may remove as well add listeners to a component.

    It ought to be fairly intuitive that a component ought to be able to have multiple listeners. After all, a text field might want to respond to both the mouse and keyboard
  675. Given the following code;

    class Base{}
    public class MyCast extends Base{
          static boolean b1=false;
          static int i = -1;
          static double d = 10.1;
          public static void main(String argv[]){
                MyCast m = new MyCast();
                Base b = new Base();
                //Here
    }}

    Which of the following, if inserted at the comment //Here, will allow the code to compile and run without error?

    1) b=m;
    2) m=b;
    3) d =i;
    4) b1 =i;
    1) b=m; and/or  3) d =i;

    You can assign up the inheritance tree from a child to a parent but not the other way without an explicit casting. A boolean can only ever be assigned a boolean value.
  676. Which of the following statements about threading are true?

    1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
    2) You can obtain a mutually exclusive lock on any object
    3) A thread can obtain a mutually exclusive lock on an object by calling a synchronized method on that object.
    4) Thread scheduling algorithms are platform dependent
    • 2) You can obtain a mutually exclusive lock on any object
    • 3) A thread can obtain a mutually exclusive lock on an object by calling a synchronized method on that object. 
    • 4) Thread scheduling algorithms are platform dependent

    Yes that says dependent and not independent.
  677. Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.

    The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?

    1) Give the goahead for further design using the current scheme
    2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
    3) Ask for the option of WindowsPC to be removed as it will soon be obsolete
    4) Change the hierarchy to remove the need for the superfluous Computer Class.
    2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type

    This question is about the requirement to understand the difference between the "is-a" and the "has-a" relationship. Where a class is inherited you have to ask if it represents the "is-a" relationship. As the difference between the root and the two children are the operating system you need to ask are Linux and Windows types of computers.The answer is no, they are both types of Operating Systems. So option two represents the best of the options. You might consider having operating system as an interface instead but that is another story.

    Of course there are as many ways to design an object hierarchy as ways to pronounce Bjarne Strousjoup, but this is the sort of answer that Sun will proabably be looking for in the exam. Questions have been asked in discussion forums if this type of question really comes up in the exam. I think this is because some other mock exams do not contain any questions like this. I assure you that this type of question can come up in the exam. These types of question are testing your understanding of the difference between the is-a and has-a relationship in class design.
  678. Which of the following statements are true?

    1) An inner class may be defined as static
    2) There are NO circumstances where an inner class may be defined as private
    3) A programmer may only provide one constructor for an anonymous class
    4) An inner class may extend another class
    • 1) An inner class may be defined as static
    • 4) An inner class may extend another class

    A static inner class is also sometimes known as a top level nested class. There is some debate if such a class should be called an inner class. I tend to think it should be on the basis that it is created inside the opening braces of another class. How could a programmer provide a constructor for an anonymous class?. Remember a constructor is a method with no return type and the same name as the class. Inner classes may be defined as private
  679. What will happen when you attempt to compile and run the following code?

    int Output=10;
    boolean b1 = false;
    if((b1==true) && ((Output+=10)==20)){
      System.out.println("We are equal "+Output);
      }else {
      System.out.println("Not equal! "+Output);
    }

    1) Compile error, attempting to peform binary comparison on logical data type
    2) Compilation and output of "We are equal 10"
    3) Compilation and output of "Not equal! 20"
    4) Compilation and output of "Not equal! 10"
    4) Compilation and output of "Not equal! 10"

    The output will be "Not equal 10".  This illustrates that the Output +=10 calculation was never performed because processing stopped after the first operand was evaluated to be false. If you change the value of b1 to true processing occurs as you would expect and the output is "We are equal 20";.
  680. Given the following variables which of the following lines will compile without error?

    String s = "Hello";
    long l = 99;
    double d = 1.11;
    int i = 1;
    int j = 0;

    1) j= i <<s;
    2) j= i<<j;
    3) j=i<<d;
    4) j=i<<l;
    2) j= i<<j;   4) j=i<<l;
  681. What will be output by the following line of code?

    System.out.println(010|4);

    1) 14
    2) 0
    3) 6
    4) 12
    4) 12

    As well as the binary OR objective this questions requires you to understand the octal notation which means that the leading letter zero (not the letter O)) means that the first 1 indicates the number contains one eight and nothing else. Thus this calculation in decimal means;  8|4

    To convert this to binary means 10000100----1100;  Which is 12 in decimal.  The | bitwise operator means that for each position where there is a 1, results in a 1 in the same position in the answer.
  682. Given the following variables;

    char c = 'c';
    int i = 10;
    double d = 10;
    long l = 1;
    String s = "Hello";

    Which of the following will compile without error?

    1) c=c+i;
    2) s+=i;
    3) i+=s;
    4) c+=s;
    2) s+=i;

    Only a String acts as if the + operator were overloaded
  683. Which of the following will compile without error?

    1) File f = new File("/","autoexec.bat");
    2) DataInputStream d = new
         DataInputStream(System.in);
    3) OutputStreamWriter o = new
         OutputStreamWriter(System.out);
    4) RandomAccessFile r = new
         RandomAccessFile("OutFile");
    • 1) File f = new File("/","autoexec.bat");
    • 2) DataInputStream d = new
    •       DataInputStream(System.in);
    • 3) OutputStreamWriter o = new
    •       OutputStreamWriter(System.out);

    Option 4, with the RandomAccess file will not compile because the constructor must also be passed a mode parameter which must be either "r" or "rw"
  684. Given the folowing classes which of the following will compile without error?

    interface IFace{}
    class CFace implements IFace{}
    class Base{}
    public class ObRef extends Base{
            public static void main(String argv[]){
                ObRef ob = new ObRef();
                Base b = new Base();
                Object o1 = new Object();
                IFace o2 = new CFace(); }}

    1) o1=o2;
    2) b=ob;
    3) ob=b;
    4) o1=b;
     
    • 1) o1=o2;
    • 2) b=ob;
    • 4) o1=b;
  685. Given the following code what will be the output?

    class ValHold{
                 public int i = 10;
    }

    public class ObParm{
    public static void main(String argv[]){
            ObParm o = new ObParm();
            o.amethod();
            }
            public void amethod(){
                    int i = 99;
                    ValHold v = new ValHold();
                    v.i=30;
                    another(v,i);
                    System.out.print( v.i );
              }//End of amethod

    public void another(ValHold v, int i){
                   i=0;
                   v.i = 20;
                   ValHold vh = new ValHold();
                   v = vh;
                   System.out.print(v.i);
         System.out.print(i);
         }//End of another}

    1) 10030
    2) 20030
    3) 209930
    4) 10020
    4) 10020

    In the callanother(v,i);  A reference to v is passed and thus any changes will be intact after this call.
  686. Given the following class definition, which of the following methods could be legally placed after the comment;

    //Here
    public class Rid{
            public void amethod(int i, String s){}
            //Here
    }

    1)public void amethod(String s, int i){}
    2)public int amethod(int i, String s){}
    3)public void amethod(int i, String mystring){}
    4) public void Amethod(int i, String s) {}
    • 1) public void amethod(String s, int i){}
    • 4) public void Amethod(int i, String s) {}

    Overloaded methods are differentiated only on the number, type and order of parameters, not on the return type of the method or the names of the parameters.
  687. Given the following class definition which of the following can be legally placed after the comment line; //Here ?

    class Base{
    public Base(int i){}
    }

    public class MyOver extends Base{
       public static void main(String arg[]){
               MyOver m = new MyOver(10);
               }
               MyOver(int i){
                       super(i);
               }

               MyOver(String s, int i){
                       this(i);
                        //Here
    }}

    1) MyOver m = new MyOver();
    2) super();
    3) this("Hello",10);
    4)Base b = new Base(10);
    4)Base b = new Base(10);

    Any call to this or super must be the first line in a constructor. As the method already has a call to this, no more can be inserted.
  688. Given the following class definition, which of the following statements would be legal after the comment //Here ?

    class InOut{
    String s= new String("Between");
              public void amethod(final int iArgs){
                  int iam;
                     class Bicycle{
                         public void sayHello(){
                         //Here
                         }
               }//End of bicycle class
          }//End of amethod
    public void another(){
                      int iOther;
    }}

    1) System.out.println(s);
    2) System.out.println(iOther);
    3) System.out.println(iam);
    4) System.out.println(iArgs);
    • 1) System.out.println(s);
    • 4) System.out.println(iArgs);

    A class within a method can only see final variables of the enclosing method. However it the normal visibility rules apply for variables outside the enclosing method.
  689. Which of the following are methods of the Thread class?

    1) yield()
    2) sleep(long msec)
    3) go()
    4) stop()
    1) yield(),  2) sleep,  4) stop()

    Note, the methods stop and suspend have been deprecated with the Java2 release, and you may get questions on the exam that expect you to know this. Check out the Java2 Docs for an explanation
  690. Which of the following methods are members of the Vector class and allow you to input a new element?

    1) addElement
    2) insert
    3) append
    4) addItem
    1) addElement
  691. Which of the following statements are true?

    1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
    2) Under no circumstances can a class be defined with the private modifier
    3) A inner class may under some circumstances be defined with the protected modifier
    4) An interface cannot be instantiated
    • 3)A inner class may under some circumstances be defined with the protected modifier
    • 4) An interface cannot be instantiated

    The import statement allows you to use a class directly instead of fully qualifying it with the full package name, adding more classess with the import statement does not cause a runtime performance overhead.

    An inner class can be defined with the protected modifier, though I am not certain why you would want to do it. An inner class can be defined with the private modifier.
  692. Which of the following are correct event handling methods?

    1) mousePressed(MouseEvent e){}
    2) MousePressed(MouseClick e){}
    3) functionKey(KeyPress k){}
    4) componentAdded(ContainerEvent e){}
    • 1) mousePressed(MouseEvent e){}
    • 4) componentAdded(ContainerEvent e){}
  693. Which of the following are methods of the Collection interface?

    1) iterator
    2) isEmpty
    3) toArray
    4) setText
    • 1) iterator
    • 2) isEmpty
    • 3) toArray
  694. Which of the following best describes the use of the synchronized keyword?

    1) Allows two process to run in paralell but to communicate with each other
    2) Ensures only one thread at a time may access a method or object
    3) Ensures that two or more processes will start and end at the same time
    4) Ensures that two or more Threads will start and end at the same time
    2) Ensures only one thread at a time may access a method or object
  695. What is an 'instanceof' ? 

    A. An operator and keyword 
    B. A methods in object
    A. An operator and keyword
  696. True/False:  Primitive datatypes are allocated on a stack
    True
  697. Following code will result in:

    int a1 = 5;
    double a2 = (float)a1;

    A) Runtime error
    B) No errors
    B) No errors
  698. What is a function in terms of Computer Science ? 

    A. A group of code lines that performs a specific task 
    B. Something that contains an 'init'
    A. A group of code lines that performs a specific task
  699. Integer a = new Integer(2);
    Integer b = new Integer(2);

    What happens when you do if (a==b)?

    A) True
    B) False
    B) False
  700. What is Java (in regard to Computer Science) ?

    A) An object-oriented programming language
    B) A MVC
    C) A subset of C
    A) An object-oriented programming language
    (this multiple choice question has been scrambled)
  701. How can you prevent a member variable from becoming serialized? 

    A. By marking it volatile 
    B. By marking it transient
    B. By marking it transient
  702. True/False:  By default, all primitive-type variables are serializable.
    True

    In a serializable class, every instance variable must be serializable.  Non-serializable instance variables must be declared transient to indicate that they should be ignored during the serialization process.
  703. What is MVC (Model View Controller)?
    MVC is an architectural pattern which separates the representation and user interaction. It’s divided into three broader sections, Model, View, and Controller. Below is how each one of them handles the task.

    • 1) The View is responsible for the look and feel.
    • 2) Model represents the real world object and provides data to the View.
    • 3) The Controller is responsible for taking the end user request and loading the appropriate Model and View.
  704. Which design pattern is most likely to be used as a proxy?

    A) value object
    B) data access object
    C) model-view-controller
    D) business delegate
    C) model-view-controller
    (this multiple choice question has been scrambled)
  705. Which design pattern reduces the number of remote network method calls required to obtain the attribute values from the entity beans?

    A) business delegate
    B) data access object
    C) model-view-controller
    D) value object
    C) model-view-controller
    (this multiple choice question has been scrambled)
  706. Which design pattern that usually is a good candidate to work with entity beans, becomes less useful when a cache is used to persist data?

    A) model-view-controller
    B) business delegate
    C) value object
    D) data access object
    A) model-view-controller
    (this multiple choice question has been scrambled)
  707. Which of the following is illegal? 

    int i = 32;
    float f = 45.0;
    double d = 45.0;
    float f = 45.0;
  708. public class Test {
    static int age;
    public static void main (String args []) {
    age = age + 1;
    System.out.println("The age is " + age);
    }}

    Which statement is true?

    A) Does not compile
    B) Compiles but generates a runtime error
    C) Compiles and runs with no output
    D) Compiles but generates a compile time error
    E) Compiles and runs printing out The age is 1
    E) Compiles and runs printing out The age is 1
    (this multiple choice question has been scrambled)
  709. Which of the following are correct? 

    a) 128 >> 1 gives 64
    b) 128 >>> 1 gives 64
    c) 128 >> 1 gives -64
    d) 128 >>> 1 gives -64
    • a) 128 >> 1 gives 64
    • b) 128 >>> 1 gives 64
  710. Which of the following return true? 

    a) "john" == "john"
    b) "john".equals("john")
    c) "john" = "john"
    d) "john".equals(new Button("john"))
    • a) "john" == "john"
    • b) "john".equals("john")
  711. Which of the following are so called "short circuit" logical operators? 

    a) &
    b) ||
    c) &&
    d) |
    • b) ||
    • c) &&
  712. Which of the following are acceptable?

    a) Object o = new Button("A");
    b) Frame f = new Panel();
    c) Boolean flag = true;
    d) Boolean flag = true;
    e) Panel p = new Applet();
    • a) Object o = new Button("A");
    • e) Panel p = new Applet();
  713. public class Test {
    static int total = 10;
    public static void main (String args []) {
    new Test();
    }
    public Test () {
    System.out.println("In test");
    System.out.println(this);
    int temp = this.total;
    if (temp > 5) {
    System.out.println(temp);
    }}} 

    Which of the following is true?

    A) The class will not compile
    B) The compiler reports an error at line 2
    C) The value 10 is one of the elements printed to the standard output
    D) The compiler reports an error at line 9
    E) The class compiles but generates a runtime error
    C) The value 10 is one of the elements printed to the standard output
    (this multiple choice question has been scrambled)
  714. Which of the following is correct: 

    A) String temp [] = new String {"j" "a" "z"};
    B) String temp [] = { "j " " b" "c"};
    C) String temp [] = {"a", "b", "c"};
    D) String temp = {"a", "b", "c"};
    C) String temp [] = {"a", "b", "c"};
    (this multiple choice question has been scrambled)
  715. What is the correct declaration of an abstract method that is intended to be public?

    A) public abstract void add();
    B) public abstract add();
    C) public abstract void add() {}
    D) public virtual add();
    A) public abstract void add();
    (this multiple choice question has been scrambled)
  716. Under what situations do you obtain a default constructor? 

    A) When you define at least one constructor
    B) When you define any class
    C) When the class has no other constructors
    C) When the class has no other constructors
    (this multiple choice question has been scrambled)
  717. Which of the following are acceptable to the Java compiler? 

    a) if (2 == 3) System.out.println("Hi");
    b) if (2 = 3) System.out.println("Hi");
    c) if (true) System.out.println("Hi");
    d) if (2 != 3) System.out.println("Hi");
    e) if (aString.equals("hello"))
            System.out.println("Hi");
    • a) if (2 == 3) System.out.println("Hi");
    • c) if (true) System.out.println("Hi");
    • d) if (2 != 3) System.out.println("Hi");
    • e) if (aString.equals("hello"))        
    •       System.out.println("Hi");
  718. Assuming a method contains code which may raise an Exception (but not a Runtime Exception), what is the correct way for a method to indicate that it expects the caller to handle that exception?

    A) throws Exception
    B) Don't need to specify anything
    C) throw Exception
    D) new Exception
    A) throws Exception
    (this multiple choice question has been scrambled)
  719. public void divide(int a, int b) {
    try {
    int c = a / b;
    } catch (Exception e) {
    System.out.print("Exception ");
    } finally {
    System.out.println("Finally");


    Which is true?

    A) Prints out: Exception Finally
    B) No output
    C) Prints out: Finally
    D) Prints out: Exception
    A) Prints out: Exception Finally
    (this multiple choice question has been scrambled)
  720. Which of the following statements is correct for a method which is overriding the following method:
    public void add(int a) {...}

    A) the overriding method can return whatever it likes
    B) the overriding method must return int
    C) the overriding method must return void
    C) the overriding method must return void
    (this multiple choice question has been scrambled)
  721. Given the following classes defined in separate files:

    class Vehicle {
    public void drive() {
    System.out.println("Vehicle: drive");
    }}

    class Car extends Vehicle {
    public void drive() {
    System.out.println("Car: drive");
    }}

    public class Test {
    public static void main (String args []) {
    Vehicle v;
    Car c;
    v = new Vehicle();
    c = new Car();
    v.drive();
    c.drive();
    v = c;
    v.drive();
    }}

    What will be the effect of compiling and running this class Test? 

    a) Generates a Compiler error on the statement v= c
    b) Generates runtime error on the statement v= c
    c) Prints out: 
         Vehicle : drive
         Car : drive
         Car : drive
    d) Prints out: 
         Vehicle : drive
         Car : drive
         Vehicle : drive
    • c) Prints out:      
    •      Vehicle : drive     
    •      Car : drive     
    •      Car : drive
  722. Where in a constructor, can you place a call to a constructor defined in the super class? 

    A) Anywhere
    B) The first statement in the constructor
    C) You can't call super in a constructor
    D) The last statement in the constructor
    B) The first statement in the constructor
    (this multiple choice question has been scrambled)
  723. Which variables can an inner class access from the class which encapsulates it? 

    a) All static variables
    b) All final variables
    c) All instance variables
    d) Only final instance variables
    e) Only final static variables
    • a) All static variables
    • b) All final variables
    • c) All instance variables
  724. What class must an inner class extend?

    A) It must extend an interface
    B) Any class or interface
    C) The top level class
    D) The Object class
    B) Any class or interface
    (this multiple choice question has been scrambled)
  725. In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected?

    public class Test { 
    public static void main (String args []) { 
        Employee e = new Employee("Bob", 48); 
        e.calculatePay(); 
    System.out.println(e.printDetails()); 
    e = null; 
    e = new Employee("Denise", 36); 
    e.calculatePay(); 
    System.out.println(e.printDetails()); 
    } }

    A) Line 7
    B) Line 8
    C) Line 11
    D) Line 10
    E) Never
    A) Line 7
    (this multiple choice question has been scrambled)
  726. What is the name of the interface that can be used to define a class that can execute within its own thread?

    A) Run
    B) Executable
    C) Thread
    D) Runnable
    E) Threadable
    D) Runnable
    (this multiple choice question has been scrambled)
  727. What is the name of the method used to schedule a thread for execution?

    A) run();
    B) init();
    C) sleep();
    D) start();
    E) resume();
    D) start();
    (this multiple choice question has been scrambled)
  728. Which methods may cause a thread to stop executing? 

    a) sleep();
    b) stop();
    c) yield();
    d) wait();
    e) notify();
    • a) sleep();
    • b) stop();
    • c) yield();
    • d) wait();
  729. Which of the following methods are defined on the Graphics class: 

    a) drawLine(int, int, int, int)
    b) drawImage(Image, int, int, ImageObserver)
    c) add(Component);
    d) drawString(String, int, int)
    e) setVisible(boolean);
    • a) drawLine(int, int, int, int)
    • b) drawImage(Image, int, int, ImageObserver)
    • d) drawString(String, int, int)
  730. Which of the following layout managers honors the preferred size of a component:

    A) GridLayout
    B) CardLayout
    C) FlowLayout
    D) BorderLayout
    C) FlowLayout
    (this multiple choice question has been scrambled)
  731. Given the following code what is the effect of a being 5:

    public class Test {
    public void add(int a) {
    loop: for (int i = 1; i < 3; i++){
    for (int j = 1; j < 3; j++) {
    if (a == 5) {
    break loop;
    }
    System.out.println(i * j);
    }}}} 

    A) Throw an ArrayIndexOutOfBoundsException
    B) Generate a runtime error
    C) Print the values: 1, 2, 2, 4
    D) Produces no output
    D) Produces no output
    (this multiple choice question has been scrambled)
  732. What is the effect of issuing a wait() method on an object 

    A) An exception will be raised
    B) The object issuing the call to wait() will be automatically synchronized with any other objects using the receiving object.
    C) The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method
    D) If a notify() method has already been sent to that object then it has no effect
    C) The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method
    (this multiple choice question has been scrambled)
  733. The layout of a container can be altered using which of the following methods: 

    A) layout(aLayoutManager);
    B) setLayoutManager(aLayoutManager);
    C) setLayout(aLayoutManager);
    D) addLayout(aLayoutManager);
    C) setLayout(aLayoutManager);
    (this multiple choice question has been scrambled)
  734. Using a FlowLayout manager, which is the correct way to add elements to a container: 

    A) add("Center", component);
    B) add(component);
    C) set(component);
    D) add(x, y, component);
    B) add(component);
    (this multiple choice question has been scrambled)
  735. Given that a Button can generate an ActionEvent which listener would you expect to have to implement, in a class which would handle this event? 

    A) ComponentListener
    B) WindowListener
    C) FocusListener
    D) ItemListener
    E) ActionListener
    E) ActionListener
    (this multiple choice question has been scrambled)
  736. Which of the following, are valid return types, for listener methods: 

    A) void
    B) the type of event handled
    C) Component
    D) boolean
    A) void
    (this multiple choice question has been scrambled)
  737. Assuming we have a class which implements the ActionListener interface, which method should be used to register this with a Button?

    A) addButtonListener(*);
    B) addListener(*);
    C) addActionListener(*);
    D) setListener(*);
    C) addActionListener(*);
    (this multiple choice question has been scrambled)
  738. In order to cause the paint(Graphics) method to execute, which of the following is the most appropriate method to call: 

    A) repaint()
    B) paint()
    C) None, you should never cause paint(Graphics) to execute
    D) update(Graphics)
    E) paint(Graphics)
    A) repaint()
    (this multiple choice question has been scrambled)
  739. Which of the following illustrates the correct way to pass a parameter into an applet:

    A) <param name=age value=33>
    B)  <applet code=Test.class age=33 width=100 height=100>
    C) <applet Test 33>
    D) <applet code=Test.class name=age value=33 width=100 height=100>
    A) <param name=age value=33>
    (this multiple choice question has been scrambled)
  740. Which of the following correctly illustrate how an InputStreamReader can be created: 

    a) new InputStreamReader(new FileInputStream("data"));
    b) new InputStreamReader(new BufferedReader("data"));
    c) new InputStreamReader(System.in);
    d) new InputStreamReader("data");
    e) new InputStreamReader(new FileReader("data"));
    • a) new InputStreamReader(new FileInputStream("data"));
    • c) new InputStreamReader(System.in);
  741. What is the permanent effect on the file system of writing data to a new FileWriter("report"), given the file report already exists? 

    A) The data is written to random locations within the file
    B) An exception is raised as the file already exists
    C) The file is replaced with a new file
    D) The data is appended to the file
    C) The file is replaced with a new file
    (this multiple choice question has been scrambled)
  742. What is the effect of adding the sixth element to a vector created in the following manner:

    new Vector(5, 10); 

    A) An IndexOutOfBounds exception is raised. 
    B) The vector grows in size to a capacity of 10 elements
    C) The vector grows in size to a capacity of 15 elements
    D) Nothing, the vector will have grown when the fifth element was added
    C) The vector grows in size to a capacity of 15 elements
    (this multiple choice question has been scrambled)
  743. What is the result of executing the following code when the value of x is 2:

    switch (x) {
    case 1:System.out.println(1);
    case 2:
    case 3:
    System.out.println(3);
    case 4:
    System.out.println(4); 

    A) The values 1, 3 and 4 are printed out
    B) The value 3 is printed out
    C) Nothing is printed out
    D) The values 3 and 4 are printed out
    D) The values 3 and 4 are printed out
    (this multiple choice question has been scrambled)
  744. What is the result of executing the following fragment of code:

    boolean flag = false;
    if (flag = true) {
    System.out.println("true");
    } else {
    System.out.println("false");
    }} 

    A) Nothing happens
    B) An exception is raised
    C) true is printed to standard out
    D) false is printed to standard out
    C) true is printed to standard out
    (this multiple choice question has been scrambled)
  745. What is the result of executing the following Java class:

    import java.awt.*;
    public class FrameTest extends Frame {
    public FrameTest() {
    add (new Button("First"));
    add (new Button("Second"));
    add (new Button("Third"));
    pack();
    setVisible(true);
    }

    public static void main(String args []) {
    new FrameTest();
    }} 

    A) Only the "first" button is displayed.
    B) A runtime exception is generated (no layout manager specified).
    C) Three buttons are displayed across a window.
    D) Only the "third" button is displayed.
    E) Only the "second" button is displayed.
    D) Only the "third" button is displayed.
    (this multiple choice question has been scrambled)
  746. Consider the following tags and attributes of tags:

    1. CODEBASE 
    2. ALT 
    3. NAME 
    4. CLASS 
    5. JAVAC 
    6. HORIZONTALSPACE 
    7. VERTICALSPACE 
    8. WIDTH 
    9. PARAM 
    10. JAR

    Which of the above can be used within the APPLET tags?

    a) line 1, 2, 3 
    b) line 2, 5, 6, 7
    c) line 3, 4, 5
    d) line 8, 9, 10
    e) line 8, 9
    • a) line 1, 2, 3 
    • e) line 8, 9
  747. Which of these are legal identifiers. Select the three correct answers;

    A) number_1
    B) number_a
    C) $1234
    D) -volatile
    • A) number_1
    • B) number_a
    • C) $1234
  748. Which of these are not legal identifiers. Select the four correct answers;

    A) 1alpha
    B) _abcd
    C) xy+abc
    D) transient
    E) account-num
    F) very_long_name
    • A) 1alpha
    • C) xy+abc
    • D) transient
    • E) account-num
  749. Which of the following are keywords in Java. Select the two correct answers;

    A) friend
    B) NULL
    C) implement
    D) synchronized
    E) throws
    • D) synchronized
    • E) throws
  750. Which of the following are Java keywords. Select the four correct answers;

    A) super
    B) strictfp
    C) void
    D) synchronize
    E) instanceof
    • A) super
    • B) strictfp
    • C) void
    • E) instanceof

    Please note that strictfp is a new keyword in Java 2.
  751. Which of these are Java keywords. Select the five correct answers;

    A) TRUE 
    B) volatile
    C) transient
    D) native
    E) interface
    F) then
    G) new
    • B) volatile
    • C) transient
    • D) native
    • E) interface
    • G) new
  752. Using up to four characters, write the Java representation of octal literal 6;
    Any of the following are correct answers - 06, 006, or 0006
  753. Using up to four characters, write the Java representation of integer literal 3 in hexadecimal;
    Any of the following are correct answers - 0x03, 0X03, 0X3 or 0x3
  754. Using up to four characters, write the Java representation of integer literal 10 in hexadecimal;
    Any of the following are correct answers - 0x0a, 0X0a, 0Xa, 0xa, 0x0A, 0X0A, 0XA, 0xA
  755. What is the minimum value of char type. Select the one correct answer;

    A) 0 
    B) - 1 -2^16
    C) -2^8
    D) -2^15
    E) -2^16 - 1
    F) -2^15
    A) 0
    (this multiple choice question has been scrambled)
  756. How many bytes are used to represent the primitive data type int in Java. Select the one correct answer;

    A) 1 
    B) The number of bytes to represent an int is compiler dependent.
    C) 8 
    D) 4 
    E) 2 
    D) 4
    (this multiple choice question has been scrambled)
  757. What is the legal range of values for a variable declared as a byte. Select the one correct answer;

    A) -127 to 128 
    B) -215 to 215 - 1
    C) 0 to 255
    D) -128 to 127
    E) 0 to 256 
    F) -128 to 128
    D) -128 to 127
    (this multiple choice question has been scrambled)
  758. The width in bits of double primitive type in Java is --. Select the one correct answer;

    A) 128 
    B) 64 
    C) 4
    D) 8 
    E) The width of double is platform dependent 
    B) 64
    (this multiple choice question has been scrambled)
  759. What would happen when the following is compiled and executed. Select the one correct answer;
     
    public class Compare {
       public static void main(String args[]) {
           int x = 10, y;
           if(x < 10)
                     y = 1;
           if(x>= 10) y = 2;
           System.out.println("y is " + y);
       }
    }

    A) The program compiles and prints y is 2 when executed. 
    B) The program compiles and prints y is 1 when executed. 
    C) The program compiles and prints y is 0 when executed. 
    D) The program does not compile complaining about y not being initialized. 
    E) The program throws a runtime exception.
    D) The program does not compile complaining about y not being initialized. 

    The variable y is getting read before being properly initialized.
    (this multiple choice question has been scrambled)
  760. What would happen when the following is compiled and executed. Select the one correct answer; 

    class example {
         int x;
         int y;
         String name;
         public static void main(String args[]) {
                example pnt = new example();
                System.out.println("pnt is " + pnt.name + " " + pnt.x + " " + pnt.y);
      }
    }

    A) The program throws a runtime exception as x, y, and name are used before initialization. 
    B) The program prints pnt is null 0 0. 
    C) The program does not compile because x, y and name are not initialized. 
    D) The program prints pnt is 0 0. 
    E) The program prints pnt is NULL false false
    B) The program prints pnt is null 0 0. 

    Instance variable of type int and String are initialized to 0 and null respectively.
    (this multiple choice question has been scrambled)
  761. The initial value of an instance variable of type String that is not explicitly initialized in the program is --. Select the one correct answer;

    A) "" 
    B) null 
    C) The instance variable must be explicitly assigned.
    D) NULL
    E) 0 
    B) null
    (this multiple choice question has been scrambled)
  762. The initial value of a local variable of type String that is not explicitly initialized and which is defined in a member function of a class. Select the one correct answer;

    A) "" 
    B) null 
    C) The local variable must be explicitly assigned.
    D) 0 
    E) NULL 
    C) The local variable must be explicitly assigned.
    (this multiple choice question has been scrambled)
  763. Which of the following are legal Java programs. Select the four correct answers;

    A)// The comments come before the packagepackage pkg;
              import java.awt.*;
              class C{}
    B) package pkg;
        import java.awt.*;
        class C{}
    C) package pkg1;
        package pkg2;
        import java.awt.*;
        class C{}
    D) package pkg;
         import java.awt.*;
    E) import java.awt.*;
        class C{}
    F) import java.awt.*;
        package pkg;
        class C {}
    • A)// The comments come before the package
    •    package pkg;         
    •    import java.awt.*;         
    •    class C{}
    • B) package pkg;   
    •     import java.awt.*;   
    •     class C{}
    • D) package pkg;     
    •      import java.awt.*;
    • E) import java.awt.*;   
    •     class C{}
  764. Which of the following statements are correct? Select the four correct answers;

    A) A Java program must have a package statement. 
    B) A package statement if present must be the first statement of the program (barring any comments).
    C) If a Java program defines both a package and import statement, then the import statement must come before the package statement. 
    D) An empty file is a valid source file. 
    E) A Java file without any class or interface definitions can also be compiled. 
    F) If an import statement is present, it must appear before any class or interface definitions.
    • B) A package statement if present must be the first statement of the program (barring any comments).
    • D) An empty file is a valid source file. 
    • E) A Java file without any class or interface definitions can also be compiled. 
    • F) If an import statement is present, it must appear before any class or interface definitions.
  765. What would be the results of compiling and running the following class. Select the one correct answer;

    class test {
         public static void main() {
             System.out.println("test");
       }
    }

    A) The program does not compile as there is no main method defined. 
    B) The program compiles and runs generating an output of "test" 
    C) The program compiles but does not run.
    D) The program compiles and runs but does not generate any output. 
    C) The program compiles but does not run.
    (this multiple choice question has been scrambled)
  766. Which of these are valid declarations for the main method? Select the one correct answer;

    A) static public void main(String); 
    B) public void main(); 
    C) public static void main(String args[]); 
    D) public static void main(String ); 
    E) public static int main(String args[]);
    C) public static void main(String args[]);
    (this multiple choice question has been scrambled)
  767. Which of the following are valid declarations for the main method. Select the three correct answers;

    A) public static void main(String args[]); 
    B) public static void main(String []args); 
    C) final static public void main (String args[]); 
    D) public static int main(String args[]); 
    E) public static abstract void main(String args[]);
    • A) public static void main(String args[]); 
    • B) public static void main(String []args); 
    • C) final static public void main (String args[]);
  768. What happens when the following program is compiled and executed with the command - java test. Select the one correct answer;

    class test {
        public static void main(String args[]) {
             if(args.length > 0)
                System.out.println(args.length);
        }
    }

    A) The program compiles and runs and prints 0 
    B) The program does not compile.
    C) The program compiles and runs but does not print anything. 
    D) The program compiles and runs and prints 2 
    E) The program compiles and runs and prints 1 
    C) The program compiles and runs but does not print anything.
    (this multiple choice question has been scrambled)
  769. What is the result of compiling and running this program? Select the one correct answer;

    public class test {
        public static void main(String args[]) {
             int i, j;
             int k = 0;
             j = 2;
             k = j = i = 1;
             System.out.println(k);
      }
    }


    A) The program does not compile as k is being read without being initialized. 
    B) The program does not compile because of the statement k = j = i = 1; 
    C) The program compiles and runs printing 0. 
    D) The program compiles and runs printing 1. 
    E) The program compiles and runs printing 2.
    D) The program compiles and runs printing 1.
    (this multiple choice question has been scrambled)
  770. What gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the one correct answer;
     
    public class test {
        public static void main(String args[]) {
          System.out.println(args[0]+"  
               "+args[args.length-1]);
       }
    }

    A) The program will print "java happens"; 
    B) The program will print "test happens" 
    C) The program will print "java test" 
    D) The program will throw an ArrayIndexOutOfBounds exception. 
    E) The program will print "lets happens"
    E) The program will print "lets happens"
    (this multiple choice question has been scrambled)
  771. What gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the one correct answer;
     
    public class test {
         public static void main(String args[]) {
             System.out.println(args[0]+"  
                   "+args[args.length]);
      }
    }

    A) The program will print "java happens"; 
    B) The program will print "java test" 
    C) The program will throw an ArrayIndexOutOfBounds exception. 
    D) The program will print "lets happens"
    E) The program will print "test happens" 
    C) The program will throw an ArrayIndexOutOfBounds exception.
    (this multiple choice question has been scrambled)
  772. What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the two correct answers;
     
    public class test {
       public static void main(String args[]) {
          System.out.println(args[0]+" " +
                  args.length);
      }
    }

    A) java 
    B) test 
    C) lets 
    D) 3 
    E) 4 
    F) 5 
    G) 6
    • C) lets 
    • E) 4
  773. What happens when the following program is compiled and run. Select the one correct answer;

    public class example {
          int i = 0;
          public static void main(String args[]) {
               int i = 1;
               i = change_i(i);
               System.out.println(i);
           }
    public static int change_i(int i) {
               i = 2;
               i *= 2;
               return i;
        }
    }

    A) The program prints 4.
    B) The program prints 0. 
    C) The program prints 1. 
    D) The program prints 2. 
    E) The program does not compile. 
    A) The program prints 4.
    (this multiple choice question has been scrambled)
  774. What happens when the following program is compiled and run. Select the one correct answer;

    public class example {
         int i = 0;
         public static void main(String args[]) {
             int i = 1;
             change_i(i);
             System.out.println(i);
        }
    public static void change_i(int i) {
             i = 2;
             i *= 2;
       }
    }

    A) The program does not compile. 
    B) The program prints 1. 
    C) The program prints 2. 
    D) The program prints 0. 
    E) The program prints 4.
    B) The program prints 1.
    (this multiple choice question has been scrambled)
  775. What happens when the following program is compiled and run. Select the one correct answer;

    public class example {
           int i[] = {0};
           public static void main(String args[]) {
                int i[] = {1};
                change_i(i);
                System.out.println(i[0]);
        }
           public static void change_i(int i[]) {
                  i[0] = 2;
                  i[0] *= 2;
          }
    }

    A) The program prints 0. 
    B) The program does not compile. 
    C) The program prints 2. 
    D) The program prints 4.
    E) The program prints 1. 
    D) The program prints 4.
    (this multiple choice question has been scrambled)
  776. What happens when the following program is compiled and run. Select the one correct answer;

    public class example {
           int i[] = {0};
           public static void main(String args[]) {
                int i[] = {1};
                change_i(i);
                System.out.println(i[0]);
        }
           public static void change_i(int i[]) {
                int j[] = {2};
                i = j;
      }
    }

    A) The program prints 2. 
    B) The program prints 4.
    C) The program prints 0. 
    D) The program prints 1. 
    E) The program does not compile. 
    D) The program prints 1.
    (this multiple choice question has been scrambled)
  777. When an unchecked exception occurs in a method but is not caught;

    1. the method-call stack is "unwound."
    2. the method terminates. 
    3. all local variables in that method go out of scope.
    4. All of the above.
    4. All of the above.
  778. To catch an exception, the code that might throw the exception must be enclosed in a ______________________.
    try block
  779. Which of the following statements is true?

    c) The throw statement is used to throw an exception.
    c) The throw statement is used to throw an exception.
  780. Chained exceptions are useful for finding out about:
    an original exception that was caught before the current exception was thrown.
  781. In the catch block below, what is arithmeticException?

    catch ( ArithmeticException arithmeticException ) {
         System.err.printf( arithmeticException );
    } // end catch
    The name of catch block's exception parameter
  782. The throws clause of a method;
    specifies the exceptions a method throws.
  783. All exception classes inherit, either directly or indirectly, from;

    A) class RuntimeException
    B) class Error
    C) class Throwable
    d) None of the above
    C) class Throwable
    (this multiple choice question has been scrambled)
  784. Which of the following statements regarding the throw point of an exception is false?

    b) It is the initial point at which the exception occurs.
    b) It is the initial point at which the exception occurs.
  785. When an exception occurs it is said to have been:
    thrown
  786. Which of the following is true?

    1. A precondition must be true when a method is invoked.
    2. A postcondition must be true when a method successfully returns to its caller.
    3. Both of the above.
    3. Both of the above.
  787. Which of the following statements is false?

    a) The finally block and try block can appear in any order.
    a) The finally block and try block can appear in any order.
  788. Which of the following exceptions is a checked exception?

    A) ArithmeticException
    B) RuntimeException
    C) InputMismatchException
    D) IOException
    D) IOException
    (this multiple choice question has been scrambled)
  789. Which of the following errors is synchronous?

    1. Divide by zero.
    2. Arithmetic overflow.
    3. Unsuccessful memory allocation. 
    4. All of the above.
    4. All of the above.
  790. Intermixing program and error-handling logic:
    can degrade a program's performance, because the program must perform (potentially frequent) tests to determine whether a task executed correctly and the next task can be performed.
  791. After a finally block has finished executing (and there are no exceptions to be handled):
    control proceeds to the first statement after the finally block.
  792. Which of the following statements is true?

    b) Like any other class, an exception class can contain fields and methods.
    b) Like any other class, an exception class can contain fields and methods.
  793. Which of the following is arranged in increasing size order?

    A) bit, field, record, file
    B) byte, field, file, record
    C) byte, file, database, record
    D) field, bit, file, record
    A) bit, field, record, file
    (this multiple choice question has been scrambled)
  794. Which of the following statements is false?

    c) Exception handling can catch but not resolve exceptions.
    c) Exception handling can catch but not resolve exceptions.
  795. Which of the following statements is true?

    1. The code in a finally block is executed only if an exception occurs. 
    2. The code in a finally block is executed only if an exception does not occur. 
    3. The code in a finally block is executed only if there are no catch blocks. 
    4. None of the above are true.
    4. None of the above are true.
  796. An uncaught exception:
    Is an exception that occurs for which there are no matching catch clauses.
  797. Which of the following statements is false?

    d) The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.
    d) The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.
  798. Consider the Java segment:

    String line1 = new String( "c = 1 + 2 + 3" ) ; StringTokenizer tok = new StringTokenizer( line1 );
    int count = tok.countTokens();

    The value of count is:
    7
  799. Which of the following is not a word character?

    A. W
    B. &
    C. _
    D. 0
    B. &
    (this multiple choice question has been scrambled)
  800. Which of the following statements is true?

    c) The length of a StringBuilder cannot exceed its capacity.
    c) The length of a StringBuilder cannot exceed its capacity.
  801. StringBuilder objects can be used in place of String objects if:

    1. The string data is not constant.
    2. The string data size may grow. 
    3. The programs frequently perform string concatenation. 
    4. All of the above.
    4. All of the above.
  802. Stream that input bytes from and output bytes to files are known as;

    A) bit-based streams
    B) Unicode-based streams
    C) character-based streams
    D) byte-based streams
    D) byte-based streams

    Programs use byte streams to perform input and output of 8-bit bytes. All byte stream classes are descended from InputStream and OutputStream . There are many byte stream classes. File I/O byte streams use FileInputStream and FileOutputStream .
    (this multiple choice question has been scrambled)
  803. To find the character at a certain index position within a String, use the method:
    charAt, with the index as an argument.
  804. Consider the Java segment:

    String line1 = new String( "c = 1 + 2 + 3" ) ; StringTokenizer tok = new
         StringTokenizer(line1, delimArg );

    For the String line1 to have 4 tokens, delimArg should be:
    String delimArg = "+=";
  805. Which of the following statements is/are true?

    1. Class Matcher provides methods find, lookingAt, replaceFirst and replaceAll. 
    2. Method matches (from class String, Pattern or Matcher) will return true only if the entire search object matches the regular expression. 
    3. Methods find and lookingAt (from class Matcher) will return true if a portion of the search object matches the regular expression.
    4. All of above.
    4. All of above.
  806. Which of the Java strings represent the regular expression ,s*?
    ",s*".
  807. Given the following declaration: StringBuilder buf = new StringBuilder(); What is the capacity of buf?
    16
  808. Given the following declarations:

    StringBuilder buf;
    StringBuilder buf2 = new StringBuilder();
    String c = new String( "test" );

    Which of the following is not a valid StringBuilder constructor?

    A. buf = new StringBuilder( buf2, 32 ); 100%
    B. buf = new StringBuilder( c ); 
    C. buf = new StringBuilder( 32 ); 
    D. buf = new StringBuilder();
    A. buf = new StringBuilder( buf2, 32 ); 100%
    (this multiple choice question has been scrambled)
  809. Which of the following is not an application of a File object?

    A) Determine if a file exists
    B) Open or edit a file
    C) Determine whether a file is writeable
    D) Determine whether a file is readable
    B) Open or edit a file
    (this multiple choice question has been scrambled)
  810. Which of the following statements is not equivalent to;

    File name = new File( "c:books2009files.txt" );

    Assume we are currently in the directory c:books.

    a) File name = new File( "files.txt" );
    a) File name = new File( "files.txt" );
  811. Which of the following statements is true?

    d) Class Scanner does not provide the ability to reposition to the beginning of the file.
    d) Class Scanner does not provide the ability to reposition to the beginning of the file.
  812. Records in a sequential file are not usually updated in place. Instead:
    the entire file is usually rewritten.
  813. What happens when an end-of-file marker is reached (and the program is using an ObjectInputStream to read data from a file)?
    An EOFException is thrown.
  814. Instance variables that are not to be output with a Serializable object are declared using which keyword?
    transient.
  815. Relative paths normally start from which directory?
    The directory in which the application began executing.
  816. What interface must a class implement to indicate that objects of the class can be output and input as a stream of bytes?
    Serializable
  817. A serialized object is:
    an object represented as a sequence of bytes used to store the object's data in a file.
  818. Which method call enables users to specify that a user can select files and directories from a JFileChooser?

    A. setFileSelectionMode( FILES_OR_DIRECTORIES ); 
    B. showOpenDialog( FILES_AND_DIRECTORIES ); 
    C. showOpenDialog( FILES_OR_DIRECTORIES );
    D. None of the above.
    D. None of the above.
  819. When an unchecked exception occurs in a method but is not caught:

    1. the method-call stack is "unwound."
    2. the method terminates. 
    3. all local variables in that method go out of scope.
    4. All of the above.
    4. All of the above.
  820. What are primitives?
    Primitives are the fundamental data type in Java.
  821. What type of primitive data type is " int " ?
    int is a primitive data type that is used to store integer values. It is the default value for whole numbers.
  822. What is the "double " primitive type used to store and is it a default?
    double is a primitive data type for large floating-point values. It is the default value for floating-point numbers.
  823. What is a boolean primitive type used to store?
    boolean is a primitive data type that is used to store true or false values.
  824. What is the char primitive data type used to store?
    char is a primitive data type that is used to store a single Unicode character.
  825. What is the " byte " primitive used to store?
    byte is a primitive used to store small numbers which are a byte (8 bits) or smaller.
  826. What is the "short" primitive used to store?
    short is a primitive used to store whole numbers up to 16 bits.
  827. What is the "long" primitive used to store?
    long is a primitive used to store large whole numbers up to 64 bits.
  828. What is the "float" primitive used to store?
    float is a primitive data type used to store floating-point values.
  829. What case are primitive data types ?
    Primitive data types all start with a lowercase letter, while classes start with an uppercase letter
  830. Each primitive data type has a corresponding this?
    They have a corresponding "Wrapper class". Each primitive data type has a corresponding wrapper class: Integer, Double, Boolean, Character, Byte, Short, Long, and Float. Notice the capital letters.
  831. What are objects and what defines them?
    Objects are more advanced data types. They may be defined by a developer or found in a built-in Java package.
  832. How are Objects initialized?
    Objects must be initialized by using the new keyword.
  833. What do Arrays allow you to store?
    Arrays allow you to store multiple variables together that can be accessed by an index.
  834. What does Enumerations allow a developer to create?
    "Enumerations allow a developer to create" a predefined set of constants. A variable can then be set only to one of the predefined values.
  835. Why Is Java a strongly typed language?
    Java is a strongly typed language because Variables must be declared as a type, and any value that is stored must be compatible with this type.
  836. Is it possible to cast a variable to a different data type?
    It is possible to cast a variable to a different data type. If incompatible types are cast, an exception will be thrown.
  837. What is a literal ?
    A literal is a value that is hard-coded in code as the value itself.
  838. What are the Java naming conventions that dictate how a "class" should be named?
    Java naming conventions dictate that a class should be named with the first letter capitalized, along with each sequential word in the name.
  839. What are the Java naming conventions that dictate how a "variable" should be named?
    Java naming conventions dictate that a variable should be named with the first letter being lowercase, and with each sequential word in the name beginning with a capital letter.
  840. True/False:  All programs have at least two threads.
    False
  841. True/False:  All the classes java.util.TimerTask and java.uti.Timer provide methods for requesting that the JVM generate threads to run scheduled tasks.
    True
  842. True/False:  Your threads can launch other threads.
    True
  843. True/False:  The JVM is in charge of scheduling processor time according to the priorities assigned to the threads.
    True
  844. True/False:  When designing a class that runs on a thread, extending Thread (as opposed to implementing Runnable) is the more flexible and usually preferred approach.
    False
  845. True/False:  The join method of the Thread class waits for the thread object to terminate.
    True
  846. True/False:  A subclass of Thread must provide an implementation of the run method because it implements the Runnable interface.
    True
  847. True/False:  The currentThread is the static method of the Thread class
    True
  848. True/False:  The sleep method of the Thread class makes the thread pause for the specified number of milliseconds.
    True
  849. True/False:  When a Thread object is constructed with a Runnable object as input, the Thread object uses the run method of the Runnable object
    True
  850. True/False:  Stopping an active thread asynchronously from the outside, by calling stop or suspend, releases all locks without giving the thread an opportunity to complete potentially critical operations.
    True
  851. True/False: Any thread that is executing can all interrupt on another thread.
    True
  852. True/False: To execute a task repeatedly, specify the period in seconds.
    False (It's milliseconds)
  853. True/False: Deadlock can occur when all threads are in a blocked state.
    True
  854. True/False: Thread-safe variables belong to one thread alone; different threads have separate copies.
    True
  855. True/False: Changes made to variable by another thread are called synchronous changes.
    False (asynchronous)
  856. True/False: Locks are the Java concept for flag maintained by the operating system.
    True
  857. True/False: You can call wait only from a method that own a key.
    False (lock)
  858. True/False: A Java application window is a frame window.
    True
  859. True/False: Containers are components that house other components.
    True
  860. True/False: GUIs use a separate thread called the event dispatched thread for drawing and forwarding all paint requests to that thread.
    True
  861. True/False: You create handlers for user-initiated events by defining classes that implement the listener interfaces.
    True
  862. True/False: The Drag and Drop API provides the ability to move data between programs created with the Java programming language.
    True
  863. True/False: To select a predefined strategy for positioning components in a container, set up an association between a class that extends LayoutManager or LayoutManager2 and a container.
    False
  864. True/False: If no listeners are registered, the event is delivered to the default listener.
    True
  865. True/False: Swing components separate the manipulation of data associated with a component from the rendering or graphical-representation component and its contents.
    True
  866. True/False: Swing uses a separable model architecture.
    True
  867. True/False: Swing-based applications extends the javax.swing.JFrame class
    True
  868. True/False: The method setDefaultCloseOperation is a member of the JFrame class.
    True
  869. True/False: Layout managers automate the positioning of the components within containers.
    True
  870. True/False: The getLocation method returns the location for the mouse event.
    False (getPoint)
  871. True/False: All components have the methods addFocusListener and add MouseListener.
    True
  872. True/False: For the listener interfaces with more than one method, you can implement the listener indirectly by extending its adapter class.
    True
  873. True/False: The paint and update methods provide a Graphic object as an argument of the method.
    True
  874. True/False: The setColor method sets the color used for subsequent drawing and fill coloring.
    True
  875. True/False: Only the Model layer operates on persistent data.
    True
  876. True/False: The properties of transactional integrity have been formalized and are known as the ACID properties.
    True
  877. True/False: A type 1 driver is called the JDBC-ODBC bridge.
    True
  878. True/False: Only type 1 drivers are portable to any JVM.
    False (Type 4)
  879. True/False: A connection from a DataSource object has the same type as one from a DriverManager object.
    True
  880. True/False: The method that issues an INSERT statement returns an integer value that indicates the number of row affected.
    True
  881. True/False: The return type of the method that issues an SELECT statement is int.
    False (ResultSet)
  882. True/False: The PreparedStatement interface extends Statement.
    True
  883. True/False: When designing a class that runs on a thread, extending Thread (as opposed to implementing Runnable) is the more flexible and usually preferred approach.
    False
  884. Can a class be declared as final?
    Yes, a class can be declared final; that is, the class cannot be sub-classed. This is done for security and design.
  885. Are instance variables assigned a default value?
    Yes, member or instance variables are always given a default value.
  886. Can you compare a boolean to an int?
    No, booleans are true and false keywords and nothing else.
  887. Can the access specifier for an overriding method allow more or less access than the overridden method?
    More. The access specifier for an overriding method can allow more, but not less, access than the overridden method.
  888. What is the difference between the default and protected access specifier?
    Default does not allow sub class access. Both allow package access.
  889. What are the access levels in order of most restrictive to least?
    Class, Package, Sub class, and World
  890. What are the access specifiers in order of most restrictive to least?
    Private, Default, Protected, and Public
  891. What is a JavaBean?
    A JavaBean is any Java class that conforms to the following rules;

    • 1) It must have an empty constructor; a constructor that accepts no parameters. If a class has no constructors at all it can qualify as a JavaBean because the default constructor has no parameters.
    • 2) It must have no public instance variables.  All the instance variables defined by the class must be either private or protected.
    • 3) It must provide methods named getProperty and setProperty to get and set any properties that the class provides, except for boolean properties that use isProperty to get the property value.

    A class does not have to have properties to be a JavaBean but if it does then the properties have to be accessed according to this naming pattern.
  892. When you pass a variable as an argument to a method call, what are you passing?
    A copy of the value. You always get a copy of whatever is in the variable - either a primitive or a reference. So for objects, you get a copy of the reference.
  893. What does break do?
    The break statement has two forms: labeled and unlabeled. An unlabeled break statement terminates the innermost switch, for, while, or do-while statement, but a labeled break terminates an outer statement.
  894. What does continue do?
    The continue statement skips the current iteration of a for, while, or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop. A labeled continue statement skips the current iteration of an outer loop marked with the given label.
  895. Where can an anonymous inner class be defined?
    An anonymous class is an expression. So anywhere an expression is used.
  896. Can overriding methods throw different exceptions than that of the super?
    Overriding methods cannot throw any new or broader exception that is checked. Unchecked does not apply.
  897. Can a private method be overridden?
    No, but it can be re-declared in the subclass. This is not polymorphism.
  898. Does each source file need a public class in it?
    No
  899. What access is the generated constructor given when one is not supplied?
    If the class is public, then it is public. Otherwise the default constructor is default.
  900. What is the keyword transient?
    It marks a member variable not to be serialized when it is persisted to streams of bytes.
  901. What is the keyword native?
    The native keyword is applied to a method to indicate that the method is implemented in native code using JNI.
  902. Will this line compile without errors?

    Object obj = new Object ();
    Yes
  903. Will this line compile without errors?

    Object [ ] obj = new Object [7];
    Yes
  904. Will this line compile without errors?

    Object obj [ ] = new Object [7];
    Yes
  905. Will this line compile without errors?

    Object obj [ ] = {new Object(), new Object()};
    Yes
  906. Will this line compile without errors?

    Object obj [ ] = {new Object [1], new Object [2]};
    Yes
  907. Will this line compile without errors?

    Object [ ] obj = new Object ();
    No.  Incorrect because they have () instead of [] after the type.
  908. Will this line compile without errors?

    Object obj [ ] = new Object() ;
    No. Incorrect because they have () instead of [] after the type.
  909. Will this line compile without errors?

    Object [ ] obj = new Object [ ];
    No.  Incorrect because they do not assign a size to the array.
  910. Will this line compile without errors?

    Object obj [ ] = new Object[ ] ;
    No. Incorrect because they do not assign a size to the array.
  911. Will this line compile without errors?

    Object [ ] obj = new Object [3]();
    No.  Incorrect because the () after the [] is not the correct syntax.
  912. Will this line compile without errors?

    Object obj [ ] = new Object [3]();
    No. Incorrect because the () after the [] is not the correct syntax.
  913. Will this line compile without errors?

    Object [8] obj = new Object [ ];
    No.  Incorrect because the size is not assigned when it is declared.
  914. Will this line compile without errors?

    Object [7] obj = new Object [7];
    No. Incorrect because the size is not assigned when it is declared.
  915. Will this line compile without errors?

    Object [3] obj = new Object [3]() ;
    No.  Incorrect because the size is in the declaration and the extra () after the [] is not the correct syntax.
  916. Will this line compile without errors?

    Object obj [] = new {new Object(), new Object()};
    No.  Incorrect because the first new operator is being used with the {} initialization method.
  917. What best describes the result of the following code segment? The ArrayList sampleArrayList has already been declared and initialized.

    int i = 63;
    sampleArrayList.add(i);
    The int is converted to an Integer via auto boxing and then placed into the ArrayList.

    Primitives cannot be stored in an ArrayList. However, if they are placed into their primitive wrapper class they can be stored. Java will automatically make that conversion via its autoboxing feature if a primitive is placed into an ArrayList.
  918. Will this line compile without errors?

    double[ ][ ][ ] numbers = new double[ ][ ][ ];
    No. When the new operator is used, at least one array dimension in a multi-dimensional array must be given a size.
  919. Will this line compile without errors?

    double[ ][ ] numbers = {{1,2,3},{7,8},{4,5,6,9}};
    Yes
  920. Will this line compile without errors?

    double[ ][ ][ ] numbers = new double[7][ ][ ];
    Yes
  921. Can a constructor have a synchronized modifier?
    No; they can never be synchronized.
  922. What is the output of the following code segment?

    int value = 1;
    switch (value) {
    case 0:
    System.out.println("Dog");

    case 1:
    System.out.println("Cat");

    case 1:
    System.out.println("Fish");

    default:
    System.out.println("Cow");
    }
    This will not compile because it includes a case statement with the same value twice.
  923. Can a constructor be declared static?
    No, constructors are for creating new instance objects. Static methods are for non-instance code, so it makes no sense to have a static constructor.
  924. Can a top-level class be marked as protected?
    No, a top-level class can only be marked public or default. The protected access is just for member variables and methods, and allows subclasses outside the superclass package to inherit the protected members.
  925. Can a constructor be declared private?
    Yes. This can be used to control the creation of the object by other less restrictive methods.
  926. True or False:  During arithmetic, when the operands are different types, the resulting type is always the widest of the two types.
    False, the result of an arithmetic operation on any two primitive operands will be at least an int -- even if the operands are byte and short.
  927. If break statements are not used in a switch, what will happen?
    Once a case statement is entered, the code will continue to execute in each case below it, until it hits a break statement.
  928. Given:

    public void simpleTest () {
    int i;
    System.out.println(i);
    }

    What will occur?
    A compiler error will occur since the value has not been initialized.
  929. Which of the following are interfaces to ArrayList? 

    a) List
    b) Map
    c) Queue
    d) RandomAccess
    e) Set
    • a) List
    • d) RandomAccess

    ;are interfaces to ArrayList.
  930. Fill in the blank. Import statements are ______.
    Required in all versions of Java.
  931. All programs can be written in terms of three types of control structures:_________, selection and repetition
    sequence
  932. All programs can be written in terms of three types of control structures:_________, sequence and repetition
    selection
  933. All programs can be written in terms of three types of control structures:_________, selection and sequence
    repetition
  934. This statement is used to execute one action when a condition is true and another when that condition is false;
    if...else
  935. Repeating a set of instructions a specific number of times is called __________ repetition.
    counter-controlled (or definite)
  936. When it's not known in advance how many times a set of statements will be repeated, a(n) __________ value can be used to terminate the repetition.
    sentinel (signal, flag or dummy)
  937. The __________ structure is built into Java; by default, statements execute in the order they appear.
    sequence
  938. Instance variables of types char, byte, short, int, long, float and double are all given the value __________ by default.
    0 (zero)
  939. Java is a(n) ________ language; it requires all variables to have a type.
    strongly typed
  940. If the increment operator is ___________ to a variable, first the variable is incremented by 1, then its new value is used in the expression.
    prefixed
  941. True/False: An algorithm is a procedure for solving a problem in terms of the actions to execute andthe order in which they execute.
    True
  942. True/False: A set of statements contained within a pair of parentheses is called a block.
    False. (A set of statements contained within a pair of braces { and } is called a block.)
  943. True/False: A selection statement specifies that an action is to be repeated while some condition remains true.
    False. (A repetition statement specifies that an action is to be repeated while some condition remains true)
  944. True/False: A nested control statement appears in the body of another control statement.
    True
  945. True/False: Java provides the arithmetic compound assignment operators +=, -=, *=, /= and %= for abbreviating assignment expressions.
    True
  946. True/False:  The primitive types (Boolean, char, byte, short, int, long, float and double) are portable across only Windows platforms.
    False. (The primitive types (Boolean, char, byte, short, int, long, float and double) are portable across all computer platforms that support Java).
  947. True/False:  Specifying the order in which statements execute in a program is called program control.
    True
  948. True/False:  The unary cast operator (double) creates a temporary integer copy of its operand.
    False. (The unary cast operator (double) creates a temporary floating-point copy of its operand).
  949. True/False:  Instance variables of type boolean are given the value true by default.
    False. (Instance variables of type boolean are given the value false by default).
  950. True/False:  Pseudocode helps you think out a program before attempting to write it in a programming language.
    True
  951. Write four different Java statements that each add 1 to integer variable x;
    • x = x + 1;
    • x += 1;
    • ++x;
    • x++;
  952. Write Java statements to accomplish the following task: Use one statement to assign the sum of x and y to z, then increment x by 1;
    z = y + x++ ( z = x++ + y;)
  953. Write Java statements to accomplish the following task:

    Test whether variable count is greater than 10. If it is, print "Count is greater than 10".
    • if ( count > 10 )
    •    System.out.println( "Count is greater than 10" );
  954. Write Java statements to accomplish the following task:

    Use one statement to decrement the variable x by 1, then subtract it from variable total and store the result in variable total.
    total -= --x;
  955. Write Java statements to accomplish the following task:

    Calculate the remainder after q is divided by divisor, and assign the result to q.

    Write this statement in two different ways
    • q %= divisor;
    • q = q % divisor;
  956. Write Java statements to accomplish the following task:

    Declare variables sum and x to be of type int
    • int sum;
    • int x;
  957. Write Java statements to accomplish the following task:

    Assign 1 to variable x
    x = 1;
  958. Write Java statements to accomplish the following task:

    Assign 0 to variable sum
    sum = 0;
  959. Write Java statements to accomplish the following task:

    Add variable x to variable sum, and assign the result to variable sum
    sum += x; or sum = sum + x;
  960. Write Java statements to accomplish the following task:

    Print "The sum is: ", followed by the value of variable sum
    System.out.printf( "The sum is: %dn", sum );
  961. Identify and correct the errors in the following code:

    while ( c <= 5 )
    {
    product *= c;
    ++c;
    Add a closing right brace after the statement ++c (Error: The closing right brace of the while statement's body is missing.)
  962. Identify and correct the errors in the following code:

    if ( gender == 1 )
    System.out.println( "Woman" );
    else;
    System.out.println( "Man" );
    Remove the semicolon after else (Error: The semicolon after else results in a logic error. The second output statement will always be executed)
  963. The __________ selection statement executes an indicated action only when the condition is true.
    if
  964. The __________ operator and the -- operator increment and decrement a variable by 1, respectively.
    ++
  965. The ++ operator and the __________ operator increment and decrement a variable by 1, respectively.
    --
  966. Output of the following statements:

    int temp;
    temp = 180;

    while ( temp != 80 ){
    if ( temp > 90 ){
    System.out.print( "This porridge is too hot! " );

    // cool down
    temp = temp - ( temp > 150 ? 100 : 20 );
    } // end if
    else{
    if ( temp < 70 ){
    System.out.print("This porridge is too cold! ");

    // warm up
    temp = temp + (temp < 50 ? 30 : 20);
    } // end if
    } // end else
    } // end while

    if ( temp == 80 )
    System.out.println( "This porridge is just right!" );
    This porridge is too hot! This porridge is just right!
  967. Java requires all variables to have a type before they can be used in a program. For this reason, Java is referred to as a(n) __________ language.
    strongly typed
  968. A dangling-else can be clarified by using:
    braces { }
  969. How many times is the body of the loop below executed?

    int counter;
    counter = 1;

    while ( counter > 20 )
    {
    // body of loop
    counter = counter + 1;
    } // end while
    0 times (zero)

    Nothing increments counter to ever make it greater than 20.
  970. If x is currently 0, a = 0 and b = -5, what will x become after the statement is executed?

    if (a > 0)
    if (b < 0)
    x = x + 5;
    else
    if (a > 5)
    x = x + 4;
    else
    x = x + 3;
    else
    x = x + 2;
    2
  971. If x is currently 0, a = 1 and b = -1, what will x become after the statement is executed?

    if (a > 0)
    if (b < 0)
    x = x + 5;
    else
    if (a > 5)
    x = x + 4;
    else
    x = x + 3;
    else
    x = x + 2;
    5
  972. If x is currently 0, a = 5 and b = 5, what will x become after the statement is executed?

    if (a > 0) 
    if (b < 0) 
    x = x + 5; 
    else 
    if (a > 5) 
    x = x + 4;
    else 
    x = x + 3;
    else
    x = x + 2;
    3
  973. True/False:  In Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably).
    False
  974. The empty statement is denoted with what symbol?
    ;
  975. True/False: The statement;

    if (a >= b) a++; else b--;

    will do the same thing as the statement;

    if (a < b) b--; else a++;
    True
  976. True/False:  The statements;

    x++; and ++x;

    will accomplish the same thing,
    but the statements;

    y = x++; and y = ++x; will not.
    True
  977. The value of the variables at the end of loop are:

    I = 5;
    J = 4;
    while (I < 10) {
    if ( (I % 3 == 0) || (I % 3 == 1) ) {
    J = J + I;
    }
    I = I + 2;
    }
    I=11,  J=20
  978. The value of the variables I, J, K at the end of the loop are:

    I = 8;
    while (I < 10) {
    J = 4;
    while (J < 6) {
    K = I + J;
    J = J + 1;
    }
    I = I + 1;
    }
    • I=10
    • J=6
    • K=14
  979. What is output by the following Java code segment?

    int temp;
    temp = 180;

    if ( temp > 90 ){
    System.out.println( "This porridge is too hot." );

    // cool down
    temp = temp - ( temp > 150 ? 100 : 20 );
    } // end if
    else
    {
    if ( temp < 70 )
    {
    System.out.println("This porridge is too cold.");

    // warm up
    temp = temp + (temp < 50 ? 30 : 20);
    } // end if
    } // end else

    if ( temp == 80 )
    System.out.println( "This porridge is just right!" );
    • "The porridge is too hot."
    • "The porridge is just right."
  980. What is output by the following Java code segment?

    int temp;
    temp = 200;

    if ( temp > 90 )
    System.out.println( "This porridge is too hot." );

    if ( temp < 70 )
    System.out.println( "This porridge is too cold." );

    if ( temp == 80 )
    System.out.println( "This porridge is just right!" );
    "The porridge is too hot"
  981. What is the result value of c at the end of the following code segment?

    int c = 8;
    c++;
    ++c;
    c %= 5;
    0 (zero)
  982. What's wrong?

    while( (i < 10) && (i > 24))
    the test condition is always false
  983. Where can local variables declared within a method's body be used?  What is their scope?
    Only in that method between the line in which they were declared and the closing brace of that method.
  984. True/False:  With the conditional operator ( ?: ) the second operand is the result value if the condition evaluates to false.
    True
  985. True/False:  "break out value" is a term used to refer to a sentinel value that breaks out of a while loop?
    False
  986. Write a statement that will add 1 to x if x is positive, and subtract 1 from x if x is negative, but leave x alone if x is 0;
    • if (x > 0) x++;
    •    else if (x < 0) x--;
  987. Typically, ___________statements are used for counter-controlled repetition and while statements for sentinel-controlled repetition.
    for
  988. Typically, for statements are used for counter-controlled repetition and __________ statements for sentinel-controlled repetition.
    while
  989. The do... while statement tests the loop-continuation condition __________ executing the loop's body; therefore, the body always executes at least once.
    after
  990. The _________ statement selects among multiple actions based on the possible values of an integer variable or expression.
    switch
  991. The __________ statement, when executed in a repetition statement, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
    continue
  992. The __________ operator can be used to ensure that two conditions are both true before choosing a certain path of execution.
    &&
  993. If the loop-continuation condition in a for header is initially __________ the program does not execute the for statement's body.
    false
  994. Methods that perform common tasks and do not require objects are called _________ methods.
    static
  995. True/False:  The default case is required in the switch selection statement.
    False
  996. True/False:  The break statement is required in the last case of a switch selection statement.
    False
  997. True/False:  The expression;

    ((x > y) && (a < b))

    is true if either (x > y) is true OR (a < b) is true.
    False
  998. True/False:  An expression containing the || operator is true if either or both of its operands is true
    True
  999. True/False:  The comma (,) formatting flag in a format specifier (e.g., %, 20.2f) indicates that a value should be output with a thousands separator.
    True
  1000. True/False:  To test for a range of values in a switch statement, use a hyphen (-) between the start and the end values of the range in a case label.
    False
  1001. True/False:  Listing cases consecutively with no statements between them enables the cases to perform the same set of statements.
    True
  1002. Write a statement: Sum the odd integers between 1 and 99, using a for statement.

    Assume that the integer variables sum and count have been declared.
    • sum =0; 
    • for ( count =1; count <=99; count +=2 ) 
    • sum += count;
  1003. Write a statement:  Calculate the value of 2.5 raised to the power of 3, using the 'pow' method
    double result = Math.pow(2. 5, 3 );
  1004. Write a statement:  Print the integers from 1 to 20, using a while loop and the counter variable i.

    Assume that i has already been declared, but not initialized. Print only 5 integers per line.
    • i=1; 
    • while (i<= 20 ) { System.out.print( i ); 
    • if (i% 5== 0 ) System.out.println();
    • else System.out.print( ' t' ); 
    • ++i; }
  1005. Write a statement:  Print the integers from 1 to 20, using a for loop and the counter variable i.

    Assume that i has already been declared, but not initialized. Print only 5 integers per line.
    • for (i=1;i<= 20; i++ ) {
    • System.out.print( i );
    • if (i% 5 == 0 ) System.out.println(); 
    • else 
    • System.out.print( ' t' ); }
  1006. Name a common programming error where a control statement uses the '<' or '>' operator when it needed the '<=' or '>=' operator.
    off-by-one error
  1007. True/False:  Class Math is defined in java.lang and does not require an import statement to be used by a program.
    True
  1008. True/False:  In a do....while statement the brackets ({ }) are used after the 'do' keyword and before the 'while' keyword, then the conditional statement is added after the 'while' keyword, followed by a (;).
    True
  1009. True or False:  A class can not implement multiple interfaces.
    False
  1010. True or False:  An interface can inherit zero or more interfaces. An interface cannot inherit a class.
    True
  1011. True or False:  A class that inherits another class is called a derived class or subclass.
    True
  1012. True or False:  A class that is inherited is called a parent or base class.
    True
  1013. True or False: Private members of a base class can be inherited in the derived class.
    False
  1014. True or False:  A derived class can only inherit members with the default access modifier if both the base class and the derived class are in the same package.
    True
  1015. True or False:  A class uses the keyword extends to inherit a class.
    True
  1016. True or False: An interface uses the keyword extends to inherit another interface.
    True
  1017. True or False: A class uses the keyword extends to implement an interface.
    False. It uses the keyword implements to implement an interface.
  1018. True or False: An interface can extend multiple interfaces.
    True
  1019. True or False: The method signatures of a method defined in an interface and in the class that implements the interface must match; otherwise, the class won't compile.
    True
  1020. True or False: With inheritance, you can also refer to an object of a derived class using a variable of a base class or interface.
    True
  1021. True or False: An object of a base class can be referred to using a reference variable of its derived class.
    False
  1022. True or False: When an object is referred to by a reference variable of a base class, the reference variable can only access the variables and members that are defined in the base class.
    True
  1023. True or False: When an object is referred to by a reference variable of an interface implemented by a class, the reference variable can access only the variables and methods defined in the interface.
    True
  1024. If the class Manager extends the class Employee, and a reference variable emp of type Employee is used to refer to an object of the class Manager, what operation can be done to access the derived class variables and methods of Manager?
    Perform a cast operation: ((Manager)emp)
  1025. True or False: If a method defines a local variable or method parameter with the same name as an instance variable, the keyword this must be used to access the instance variable in the method.
    True
  1026. What are the conditions for a method to be polymorphic?
    The polymorphic methods are also called overridden methods. Overridden methods should define methods with the same name, same argument list, same list of method parameters. The return type of the overriding method can be the same, or a subclass of the return type of the overridden method in the base class, which is also known as covariant return type. Access modifiers for an overriding method can be the same or less restrictive but can't be more restrictive than the method being overridden.
  1027. What conditions must a method meet to be an overridden one?
    A derived class is said to override a method in the base class if it defines a method with the same name, same parameter list, and same return type as in the derived class.
  1028. True or False: If a method defined in a base class is overloaded in the derived classes, then these two methods (in the base class and the derived class) are called polymorphic methods.
    False. Only overridden methods can be called polymorphic.
  1029. True or False: When implementing polymorphism with classes, a method defined in the base class may or may not be abstract.
    True
  1030. True or False: When implementing polymorphism with interfaces, a method defined in the base interface is always abstract.
    True
  1031. Explain "Reference Type" and "Object Type"
    The reference type corresponds to the type in a variable declaration. The object type corresponds to the instantiated class in an object variable declaration. So "reference type" is the LHS type and "object type" is the actual instantiated type on the RHS of an object variable declaration.
  1032. True or False: The super keyword can be used to invoke super class methods in the subclass's overloaded methods?
    True
  1033. True or False: This statement will compile "( (Object)newString.toString("Foo") )" where class NewString has overloaded method "String toString(String arg)".
    False. The cast to Object will fail to compile since the Object class does not have a toString(String) method.
  1034. True or False: The reference type determines which members of a variable object are accessible
    True. Only those members allowing access according to their access modifiers will be available to be called. Furthermore, only those available methods are candidates for polymorphic calls.
  1035. True or False: A class with a private constructor can be inherited.
    False
  1036. True or False: The invocation of the base class' default constructor occurs automatically unless we use the super keyword to invoke an alternative base class constructor.
    True
  1037. Can a subclass override a method and declare fewer thrown exceptions than the superclass method?
    Yes, it is legal. The overriding method does not have to declare "throws" on checked exceptions declared by the super class.
  1038. For overloaded methods, is it the reference type or dynamic runtime object type that determinesl which method gets called?
    The reference type (not the object type) determines which overloaded method is invoked!
  1039. True or False: constructors are inherited by the subclass.
    False. Never.
  1040. What is the order of execution of instance initializers and constructors-in base and subclasses? Constructors first or initializers?
    Each class will have its initializers called first, before the constructor. The super class constructor will be called first, implicitly or excplicitly, before the subclass.
  1041. Can instance initializers be inherited by a derived class?
    No. The instance initializers can't be defined with any explicit access. They can only be defined using the 'default' access. Also, instance initializers aren't inherited by derived class. They execute when a class is instantiated.
  1042. What is the access modifier for the default constructor?
    The default constructor is the no-arg one provided by the JVM. It will be assigned the same access modifier as the specified for the class itself.
  1043. When can a child class in another package access a protected member in the parent class?
    Only when the child tries to access it own variable, not variable of other instance
  1044. True or False: An abstract method can not be overridden.
    False. Abstract methods are meant to be overridden by subclasses.
  1045. When are static instance blocks executed in an objects lifecycle?
    Immediately after the call to super's constructor and before the instance constructor's code. Blocks are called in top to bottom order.
  1046. True or False: You can define only one variable argument in a parameter list, and it should be the final variable in the parameter list. If these two rules aren't followed, your code won't compile.
    True
  1047. True of False: It is valid to have code that can be executed only after a return statement.
    False. The class will fail to compile.
  1048. What is an overloaded method?
    Overloaded methods accept different lists of arguments. The argument lists can differ by:

    • - Changes in the number of parameters that are accepted
    • - Changes in the types of parameters that are accepted
    • - Changes in the positions of parameters that are accepted
  1049. True or False: Methods can be defined as overloaded methods if they differ only in their return types or access modifiers.
    False
  1050. Define Constructor.
    Constructors have the same name as the class, and they create and return an instance of the class in which they are defined. They don't specify a return type—not even void.
  1051. What are the three steps to reading contents of a file in the Java IO file management system?
    open, read, close
  1052. What is the import format for file management including BufferedReader?
    import java.io.*;
  1053. What is the syntax of the contractor for buffered reader called rd?
    BufferedReader rd = new BufferedReader(new FileReader("text.txt"));
  1054. What is the standard idiom or line of code that closes a BufferedReader rd after reading the contents?
    rd.close();
  1055. What are two different ways of instantiating Buffered readers/writers?
    • Chained constructors:
    • new BufferedReader(new FileReader(new File("foo.txt")));

    • Files util:
    • Files.newBufferedWriter(myPath, Charset.forName("UTF-8"),
    • new OpenOption[]{StandardOpenOption.APPEND,StandardOpenOption.DSYNC})
  1056. True or False: Once created there is no way to change the file or directory that the File object represents.
    True.

    Instances of the File class are immutable; that is, once created, the abstract pathname represented by a File object will never change. The path variable of the File class has no setter, it is set only in the constructor.
  1057. What attributes are supported by the BasicFileAttributeView.class?
    • Name / Type
    • "lastModifiedTime" FileTime
    • "lastAccessTime" FileTime
    • "creationTime" FileTime
    • "size" Long
    • "isRegularFile" Boolean
    • "isDirectory" Boolean
    • "isSymbolicLink" Boolean
    • "isOther" Boolean
    • "fileKey" Object
  1058. What attributes are supported by the DosFileAttribuesView.class?
    • Name / Type
    • readonly Boolean
    • hidden Boolean
    • system Boolean
    • archive Boolean
  1059. Discuss the class hierarchy of RandomAccessFile;
    RandomAccessFile does not extend from InputStream or OutputStream. But it does implement java.io.DataOutput and java.io.DataInput interfaces (and Closeable and AutoCloseable interfaces as well).
  1060. If a class includes a package statement, where must it be placed?
    The first statement of the class file
  1061. What are the two ways a class can use another packages classes?
    • 1. By declaring an import statement of the fully qualified package + class name
    • 2. By delcaring a variable of the class type using the fully qualifed package + class name
  1062. True or False: comments can appear anywhere in a class file, including before the package statement.
    True
  1063. How is the state and behavior of a Java class defined?
    • State is defined through the instance variables or attributes.
    • Behavior is defined through methods.
  1064. True or False: A Java source code file can defined more than one public class or interface?
    False
  1065. True or False: If a public class or interface is defined in a Java source code file, then the name of that filemust match the name of the public class or interface.
    True
  1066. In the world of computer programming and design patterns, who were the "gang of four"?
    Design Patterns: Elements of Reusable Object-Oriented Software is a software engineering book describing recurring solutions to common problems in software design. The book's authors are Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides with a foreword by Grady Booch. The book is divided into two parts, with the first two chapters exploring the capabilities and pitfalls of object-oriented programming, and the remaining chapters describing 23 classic software design patterns. The book includes examples in C++ and Smalltalk.
  1067. In their book, the Gang of Four outlined how many different design patterns?
    23
  1068. According to the Gang of Four, what two design techniques are outlines to lead to good object-oriented software design?
    "Program to an 'interface', not an 'implementation'." (Gang of Four 1995:18)

    "Favor 'object composition' over 'class inheritance'." (Gang of Four 1995:20)
  1069. What are the 3 primary areas of focus for Object Oriented Programming (OOP)?
    • Encapsulation
    • Inheritance
    • Polymorphism
  1070. With polymorphism we can design and implement systems that are easily ________________.
    extensible.

    • New classes can be added with little or
    • no modification to the general portions of the program, as long as the new classes are part of the inheritance hierarchy that the program processes generically.

    The only parts of a program that must be altered to accommodate new classes are those that require direct knowledge of the new classes that we add to the hierarchy.
  1071. True/False:  Abstract classes cannot be used to instantiate objects - abstract classes are incomplete.
    True

    Subclasses must declare the “missing pieces” to become “concrete” classes, from which you can instantiate objects; otherwise, these subclasses, too, will be abstract.
  1072. Classes that can be used to instantiate objects are called ______________________.
    concrete classes
  1073. Which UML document specifies the purpose of an application/system and what it must do?
    A requirements document specifies the purpose of an application/system and what it must do.
  1074. What UML document models the interactions between a system's clients and its use cases?
    A use case diagram models the interactions between a system’s clients and its use cases.

    It shows the kinds of interactions users have with a system without providing the details.

    Often accompanied by informal text that gives more detail—like the text that appears in the requirements document.

    Produced during the analysis stage of the software life cycle.
  1075. A _____________ is a set of component that interact to solve a problem.
    system
  1076. _________________________ describes the systems objects and their relationships.
    system structure
  1077. _________________________ describes how the system changes as its objects interact with each other.
    system behavior
  1078. Every system has both ___________ and _________.  Designers must specify both.
    • Every system has both structure and
    • behavior—Designers must specify both.
  1079. The UML 2 standard specifies _____ diagram types for documenting the system models.
    The UML 2 standard specifies 13 diagram types for documenting the system models.

    Each models a distinct characteristic of a system’s structure or behavior—six diagrams relate to system structure, the remaining seven to system behavior.
  1080. _________________________________ model the ways in which an object changes state. An object’s state is indicated by the values of all its attributes at a given time. When an object changes state, it may behave differently in the system.
    State machine diagrams
  1081. What are UML Activity Diagrams?
    They show the flow of control
  1082. How are Activity Diagrams represented?
    Rounded Rectangles.
  1083. What is a Use-Case diagram?
    Shows what is the outside the system (actors) and the functionality that the system must provide (use cases)
  1084. What are the three phases or levels of design models?
    • CONCEPTUAL DESIGN
    • Choose a modelling language and generate a conceptual model to represent the business activities.
    • LOGICAL DESIGN
    • Schemas and keys, relational or object oriented, logical design
    • PHYSICAL DESIGN
    • Create the tables in the DBMS including defining domains, creating indexes, defining domains etc.
  1085. Which of the following statements is false?

    A) Data is lost when a local variable "goes out of scope."
    B) Storage of data variables and arrays is temporary.
    C) Data maintained in files is often called transient data.
    D) Files are used for long-term retention of large amounts of data.
    C) Data maintained in files is often called transient data.
    (this multiple choice question has been scrambled)
  1086. File processing programs are generally implemented in Java as __________.

    A. Multithreaded programs.
    B. Applications.
    C. Applets.
    D. Interfaces.
    B. Applications.
    (this multiple choice question has been scrambled)
  1087. Which statement is false?

    A. Java Unicode characters are composed of 2 bytes each.
    B. A record is typically composed of several fields.
    C. The term "bit" is short for "byte digit."
    D. The smallest data item in a computer can assume the value 0 or the value 1.
    C. The term "bit" is short for "byte digit."
    (this multiple choice question has been scrambled)
  1088. __________ is an I/O performance enhancement technique.

    A. Transaction processing.
    B. Piping.
    C. Pushback.
    D. Buffering.
    D. Buffering.
    (this multiple choice question has been scrambled)
  1089. __________ are synchronized communication channels between threads.

    A. Buffers.
    B. Pipes.
    C. Files.
    D. Interfaces.
    B. Pipes.
    (this multiple choice question has been scrambled)
  1090. How do methods setIn, setOut and setErr affect the standard input, output and error streams?

    A. They wrap the streams around another stream.
    B. They flush these streams’ buffers.
    C. They redirect the standard input, output and error streams.
    D. They toggle the buffering capability of these streams.
    C. They redirect the standard input, output and error streams.
    (this multiple choice question has been scrambled)
  1091. System.out and System.err are objects of what class?

    A. FileOutputStream. 
    B. PrintStream.
    C. BufferedOutputStream.
    D. PipedOutputStream.
    B. PrintStream.
    (this multiple choice question has been scrambled)
  1092. Which of the following is not an application of a File object?

    A. Determine whether a file is readable.
    B. Determine whether a file is writable.
    C. Open or edit a file.
    D. Determine if a file exists.
    C. Open or edit a file.
    (this multiple choice question has been scrambled)
  1093. To insert a in a string literal you must use __________.

    A. ".
    B. /.
    C. .
    D. //.
    C. .
    (this multiple choice question has been scrambled)
  1094. Relative paths start from which directory?

    A. The directory in which the Java interpreter is installed.
    B. The root directory.
    C. The directory in which the application began executing.
    d. None of the above.
    C. The directory in which the application began executing.
    (this multiple choice question has been scrambled)
  1095. Adding the services of one stream to another is known as;

    A. chaining.
    B. wrapping.
    C. adding.
    D. sequencing.
    B. wrapping.
    (this multiple choice question has been scrambled)
  1096. Which statement regarding Java files is false?

    A. Java imposes no structure on a file.
    B. The programmer must structure files to meet the requirements of applications.
    C. Notions like "record" do not exist in Java files.
    D. Records in a Java sequential file are stored in order by record key.
    D. Records in a Java sequential file are stored in order by record key.
    (this multiple choice question has been scrambled)
  1097. When displayed, a JFileChooser dialog does not allow the user to interact with any other program window until the JFileChooser dialog is closed. Dialogs that behave in this fashion are called __________ dialogs.

    A. Choice.
    B. Modal.
    C. Median.
    D. Synchronized.
    B. Modal.
    (this multiple choice question has been scrambled)
  1098. What interface allows objects to be converted to a series of bytes?

    A. Synchronized.
    B. Serializable.
    C. Permanent.
    D. Output.
    B. Serializable.
    (this multiple choice question has been scrambled)
  1099. Instance variables that are not to be output with that object are declared using which keyword?

    A. private.
    B. temporary.
    C. transient.
    D. ignore.
    C. transient.
    (this multiple choice question has been scrambled)
  1100. RandomAccessFile method __________ repositions the file-position pointer to any position in the file.

    A. set.
    B. search.
    C. seek .
    D. serve.
    C. seek .
    (this multiple choice question has been scrambled)
  1101. What happens when an end-of-file marker is reached?

    A. An end-of-file character is read by the program.
    B. An EOFException is thrown.
    C. Nothing occurs.
    D. The program crashes.
    B. An EOFException is thrown.
    (this multiple choice question has been scrambled)
  1102. The file-position pointer;

    A. is a reference to a File object.
    B. always points to the beginning of the file.
    C. points to the next byte in the file to be read or written to.
    D. always points to the end of the file.
    C. points to the next byte in the file to be read or written to.
    (this multiple choice question has been scrambled)
  1103. When a file is opened, the file-position pointer;

    A. points to the end of the file.
    B. points to the beginning of the file.
    C. is undefined.
    D. is positioned where it was when the file was closed.
    B. points to the beginning of the file.
    (this multiple choice question has been scrambled)
  1104. Which statement is false?

    A. Updating a large portion of a sequential-access file is a relatively efficient operation.
    B. Updating only a small portion of a sequential-access file is a relatively efficient operation.
    C. Updating a sequential-access file typically involves copying the file.
    D. Updating only a small portion of a sequential-access file is a relatively expensive operation.
    B. Updating only a small portion of a sequential-access file is a relatively efficient operation.
    (this multiple choice question has been scrambled)
  1105. Which statement is true?

    A. Sequential-access files are appropriate for "instant-access" applications.
    B. Transaction-processing systems are good examples of "instant-access" applications.
    C. Airline reservation systems, point-of-sale systems, and automated teller machines are best implemented as sequential-access applications.
    D. Data cannot be inserted in a random-access file without destroying other data in the file.
    B. Transaction-processing systems are good examples of "instant-access" applications.
    (this multiple choice question has been scrambled)
  1106. Random-access files are sometimes called;

    A. direct-access files.
    B. sequential-access files.
    C. instant-access files.
    d. None of the above.
    A. direct-access files.
    (this multiple choice question has been scrambled)
  1107. When a RandomAccessFile stream is associated with a file, data is read or written beginning at the location in the file specified by the __________.

    A. File-location pointer.
    B. Transaction pointer.
    C. Read/write pointer.
    D. File-position pointer.
    D. File-position pointer.
    (this multiple choice question has been scrambled)
  1108. Which statement is false?

    A. Swing components display null byte characters as rectangles.
    B. The file open mode for a RandomAccessFile can be "w" to open the file for writing.
    C. The file open mode for a RandomAccessFile can be "rw" to open the file for reading and writing.
    D. The file open mode for a RandomAccessFile can be "r" to open the file for reading.
    B. The file open mode for a RandomAccessFile can be "w" to open the file for writing.
    (this multiple choice question has been scrambled)
  1109. True/False:  To save data permanently within a Java program, or to retrieve that data later, you must use at least one stream.
    True
  1110. What is a stream?
    A stream is an object that takes information from one source and sends it to another. The name is inspired by streams that take fish, boats, inner tube riders, and industrial pollutants from one place to another.

    Streams connect a diverse variety of sources, including computer programs, hard drives, Internet servers, computer memory, and CD-ROMs. Because all these things use streams, once you learn how to work with one kind of data, you will be able to work with others in the same manner.
  1111. What are the 2 kinds of streams?
    • * Input streams, which read data from a source
    • * Output streams, which write data to a source
  1112. True/False:  All input and output streams are made up of bytes, individual integers with values ranging from 0 to 255.
    True

    All input and output streams are made up of bytes, individual integers with values ranging from 0 to 255. You can use this format to represent data, such as executable programs, word-processing documents, and MP3 music files, but those are only a small sampling of what bytes can represent. A byte stream is used to read and write this kind of data.
  1113. Java classes are stored as bytes in a form called _____________________.
    bytecode

    The Java interpreter runs bytecode, which doesn't actually have to be produced by the Java language. It can run compiled bytecode produced by other languages, including NetRexx and JPython. You will also hear the Java interpreter referred to as the "bytecode interpreter."
  1114. Whether you work with a stream of bytes, characters, or other kinds of information, the overall process is the same.  What are these 3 steps in the process?
    • 1. You create a stream object associated with the data.
    • 2. You call methods of the stream to either put information in the stream or take information out of it.
    • 3. You close the stream by calling the object's close() method.
  1115. True/False:  In Java, files are represented by the File class, which also is part of the java.lang package.
    False

    In Java, files are represented by the File class, which also is part of the java.io package.

    Files can be read from hard drives, floppy drives, CD-ROMs, and other storage devices.
  1116. What abstract data type is the ancestor of all streams that input byte-oriented data?

    A.    BufferedByteInputStream
    B.    ByteReader
    C.    InputStream 
    D.    ByteInputStream
    C.    InputStream
    (this multiple choice question has been scrambled)
  1117. Which of the following opens the file "myData.stuff" for Input?

    A. FileInputStream fis = new FileInputStream( "myData.stuff")
    B. FileInputStream fis = new FileInputStream( "myData.stuff", true)
    C. FileInputStream fis = new FileInputStream( new BufferedInputStream( "myData.stuff") )
    D. DataInputStream dis = new DataInputStream( "myData.stuff" )
    A. FileInputStream fis = new FileInputStream( "myData.stuff")
    (this multiple choice question has been scrambled)
  1118. What is the DataInputStream method that reads an int value?

    A.    ReadInt()
    B.    readInt()
    C.    read()
    D.    ReadInteger()
    B.    readInt()
    (this multiple choice question has been scrambled)
  1119. Say that a file was created using many calls to DataOutputStream.writeInt(). Is it possible to read that file with DataInputStream.readDouble()?

    A.    No---the hardware will not let this happen.
    B.    Yes--nothing wrong in doing that.
    C.    Yes--although the results almost certainly will be wrong.
    D.    No---the compiler will not let this happen.
    C.    Yes--although the results almost certainly will be wrong.
    (this multiple choice question has been scrambled)
  1120. In practice, is it always possible to know how to interpret the bytes in a given file?

    A.    Yes--all you need to do is try all possible interpretations until you find the one that works.
    B.    No---because byte patterns can mean almost anything and often documentation is poor or missing.
    C.    No---files from one type of computer can't be read by any other type.
    D.    Yes--data and file formats are the same with all programs on all computers.
    B.    No---because byte patterns can mean almost anything and often documentation is poor or missing.
    (this multiple choice question has been scrambled)
  1121. Is input and output with binary files slower or faster than with character-oriented files?

    A.    Faster---because binary data does not use a buffer.
    B.    Faster---because binary data is more compact and does not need translation.
    C.    Slower---because primitive data must be translated into characters when doing IO.
    D.    Slower---because primitive data take more memory than characters.
    D.    Slower---because primitive data take more memory than characters.
    (this multiple choice question has been scrambled)
  1122. What data type does DataInputStream.readUnsignedByte() evaluate to?

    A.    Byte
    B.    int
    C.    null
    D.    byte
    B.    int
    (this multiple choice question has been scrambled)
  1123. What happens when DataInputStream.readLong() reaches the end of the input file?

    A.    A null value is returned.
    B.    Control automatically leaves the program.
    C.    The program crashes.
    D.    An EOFException is thrown.
    D.    An EOFException is thrown.
    (this multiple choice question has been scrambled)
  1124. It it possible to make a copy of a file without knowing the format of the data it contains?

    A.    Yes--any file can be copied as long as all the data is the same type.
    B.    Yes--a byte-by-byte copy works for all data.
    C.    No---you must know what each byte means in order to copy it to a file.
    D.    No---files must have a header that describes the rest of the bytes.
    B.    Yes--a byte-by-byte copy works for all data.
    (this multiple choice question has been scrambled)
  1125. What happens when the constructor for FileInputStream fails to open a file for reading?

    A.    It throws a ArrayIndexOutOfBoundsException.
    B.    It throws a FileNotFoundException.
    C.    It throws a DataFormatException.
    D.    It returns null.
    B.    It throws a FileNotFoundException.
    (this multiple choice question has been scrambled)
  1126. What is the best definition of a binary file?

    A.    A file that does not contain any bytes that represent characters.
    B.    A file that only contains bytes.
    C.    A file who's bytes might contain any pattern of ones and zeros.
    D.    A file who's bytes contain only ones and zeros.
    C.    A file who's bytes might contain any pattern of ones and zeros.
    (this multiple choice question has been scrambled)
  1127. How many patterns can be formed from 8 bits?

    A.    16
    B.    64
    C.    8
    D.    256 == 28
    D.    256 == 28
    (this multiple choice question has been scrambled)
  1128. What abstract data type is the ancestor of all streams that output byte-oriented data?

    A.    ByteStream
    B.    OutputStream 
    C.    BinaryOutputStream 
    D.    ByteOutputStream
    B.    OutputStream
    (this multiple choice question has been scrambled)
  1129. Which of the following opens the file "myData.stuff" for output first deleting any file with that name?

    A.    FileOutputStream fos = new FileOutputStream( "myData.stuff", true )
    B.    FileOutputStream fos = new FileOutputStream( "myData.stuff")
    C.    FileOutputStream fos = new FileOutputStream( new BufferedOutputStream( "myData.stuff") )
    D.    DataOutputStream dos = new DataOutputStream( "myData.stuff" )
    B.    FileOutputStream fos = new FileOutputStream( "myData.stuff")
    (this multiple choice question has been scrambled)
  1130. What is an advantage of using a DataOutputStream?

    A.    A DataOutputStream translates primitive data into characters.
    B.    A DataOutputStream need not be used with other streams.
    C.    A DataOutputStream uses the particular data format of the computer it is running on.
    D.    A DataOutputStream has convenient methods for output of primitive data types.
    D.    A DataOutputStream has convenient methods for output of primitive data types.
    (this multiple choice question has been scrambled)
  1131. What is the name of the printed output of a program that shows the byte-by-byte contents of a binary file?

    A.    Charmed Display
    B.    Pattern Listing
    C.    Binary Refuse
    D.    Hex Dump
    D.    Hex Dump
    (this multiple choice question has been scrambled)
  1132. A program writes ten int values to a new file. How many bytes long is the file?

    A.    40
    B.    10
    C.    Depends on the size of the values in the ints.
    D.    20
    A.    40
    (this multiple choice question has been scrambled)
  1133. What is the DataOutputStream method that writes double precision floating point values to a stream?

    A.    writeFloat()
    B.    writeBytes()
    C.    write()
    D.    writeDouble()
    D.    writeDouble()
    (this multiple choice question has been scrambled)
  1134. One of the bit patterns that an int variable might hold, as it might be written on paper or on a blackboard, is:

    00000000 01010101 11111111 00001111

    Which eight bits are the low-order byte?

    A.    01010101
    B.    11111111 
    C.    00001111
    D.    00000000 
    C.    00001111
    (this multiple choice question has been scrambled)
  1135. What  DataOutputStream method reports the number of bytes written to a stream so far?

    A.    length()
    B.    size()
    C.    written()
    D.    flush()
    B.    size()
    (this multiple choice question has been scrambled)
  1136. The action of reading data from a file is known as _____________.

    A) File I/O
    B) File Output
    C) Saving
    D) File Input
    D) File Input
    (this multiple choice question has been scrambled)
  1137. The two types of file access operations are _________________.

    A) Read access and write access
    B) Public access and private access
    C) Protected access and private access
    D) Public access and protected access
    A) Read access and write access
    (this multiple choice question has been scrambled)
  1138. Assume we wish to represent a file named, “hello” with the symbol, x.  How would we do it?

    A) Directory hello = new File(x);
    B) File x = new File(“hello”);
    C) File hello = new File(x);
    D) Directory x = new Directory(“hello”);
    B) File x = new File(“hello”);
    (this multiple choice question has been scrambled)
  1139. Using the File class, how would you open a file named “Jenny.data” that is stored in the directory, “C:/mystuff”?

    A) File x = new File(“C:/mystuff”, “Jenny.data”);
    B) File x = new File(“C:/mystuff/Jenny.data”);
    C) File x = new File(“Jenny.data”, “C:/mystuff”);
    D) File x = new File(“mystuff”,”Jenny.data”);
    A) File x = new File(“C:/mystuff”, “Jenny.data”);
    (this multiple choice question has been scrambled)
  1140. What is the difference in path name specification between the UNIX and Windows operating systems?

    A) There are no .exe files in UNIX but there are .exe files in Windows
    B) UNIX separates directories from subdirectories with forward slashes while Windows separates directories with backslashes.
    C) There is no difference
    D) UNIX allows for spaces in file and directory names while Windows does not.
    B) UNIX separates directories from subdirectories with forward slashes while Windows separates directories with backslashes.
    (this multiple choice question has been scrambled)
  1141. Assume you are in a directory;
     
    C:/a/b/c/d/

    and wish to execute the file;

    C:/a/yes.data 

    Which of the following is an invalid method to perform the execution?

    a) Shell>>cd ..
        Shell>>cd ..
        Shell>>cd ..
        Shell>>yes.data
    b) Shell>>../../../yes.data
    c) Shell>>/a/yes.data
    d) Shell>>yes.data
    d) Shell>>yes.data
  1142. Assume you want to list the contents of the directory, “C:/myDocs”.  How would you do this?

    A) System.out.println(File.list(“myDocs”));
    B) System.out.println(dir.list());
    C) File dir = new File(“C:/myDocs”);
    System.out.println(dir.list());
    d) File dir = new File(“C:/myDocs/*.*”);
    System.out.println(dir);
    C) File dir = new File(“C:/myDocs”);System.out.println(dir.list());
    (this multiple choice question has been scrambled)
  1143. Consider the following block of code.  What is the output?  (Assume all files in this operating system have extensions.)

    File file = new File(“C:/papers/stuff”);
    if (file.isFile()){
      System.out.println(“I am a file”);
    }
    else{
      System.out.println(“I am a directory”);
    }
    System.out.println(“I am done”);
     
    a) I am a file
        I am done
    b) I am a directory
        I am done
    c) I am done
    d) I am a file
    • b) I am a directory   
    •     I am done
  1144. Assume you open a Web browser and right-click a picture on any Website.  You then click on save target as…  Notice the new window that pops up.  Which Java Swing object would allow a programmer to create such a pop up window?

    A) JFile
    B) FileTextBox
    C) JFileChooser
    D) FileChooser
    C) JFileChooser
    (this multiple choice question has been scrambled)
  1145. Which method of the FileChooser class should you use to filter files from a list of files?

    A) filter
    B) accept
    C) parse
    d) None of the above
    B) accept
    (this multiple choice question has been scrambled)
  1146. In the file “hello.java”, “java” is the ___________ of the file name.

    A) extension
    B) class
    C) type
    D) header
    A) extension
    (this multiple choice question has been scrambled)
  1147. A(n) _________ is a sequence of data items, usually 8-bit bytes.

    A) input
    B) stream
    C) output
    D) destination
    B) stream
    (this multiple choice question has been scrambled)
  1148. Once we have opened a file for access in a Java program, which of the following objects is needed to write to the file?

    A) FileInputStream
    B) FileOutputStream
    C) BufferedInputReader
    D) BufferedStringWriter
    B) FileOutputStream
    (this multiple choice question has been scrambled)
  1149. The operation of saving data as a block is known as ____________.

    A) data caching
    B) block saving
    C) blocking
    D) data grouping
    A) data caching
    (this multiple choice question has been scrambled)
  1150. At the end of any file access operation, input or output, what action should be taken to ensure that all data was saved to the file?

    A) output the file contents
    B) close the file streams
    C) open the file and check the contents
    d) None of the above
    B) close the file streams
    (this multiple choice question has been scrambled)
  1151. Assuming that outStream is a properly declared FileOutputStream object, what is wrong with the following code?

    byte[] byteArray= { (byte)’Y’, (byte)’E’,(byte)’S’};
    outStream(print(byteArray);
    outStream.close();

    A) single characters are not permitted to be cast to byte objects.
    B) the fileStream is not closed properly
    C) print is not a valid method of the FileOutputStream class.
    D) one cannot send an entire array into the print method.
    C) print is not a valid method of the FileOutputStream class.
    (this multiple choice question has been scrambled)
  1152. In order to print primitive data types to a file without having to convert them into bytes, one can use the _____________ class.

    A) DataInputStream
    B) DataOutputStream
    C) FileInputStream
    D) FileOutputStream
    B) DataOutputStream
    (this multiple choice question has been scrambled)
  1153. Assume you want to read the contents of a file and display to the monitor.  Which file I/O classes can we use to accomplish this?

    A) DataInputStream or DataOutputStream
    B) FileInputStream or DataInputStream
    C) FileInputStream or FileOutputStream
    D) FileOutputStream or DataOutputStream
    B) FileInputStream or DataInputStream
    (this multiple choice question has been scrambled)
  1154. What type of file format is a text editor capable of interpreting?

    A) machine language
    B) binary
    C) ASCII
    D) human language
    C) ASCII
    (this multiple choice question has been scrambled)
  1155. If you want to perform an object I/O then the class definition must include the phrase _________________.

    A) throws Serializable
    B) ObjectInputStream
    C) ObjectOutputStream
    D) implements Serializable
    D) implements Serializable
    (this multiple choice question has been scrambled)
  1156. True or false?  With object I/O, data are read and saved as objects.
    True
  1157. True or false?  The lowest level of file I/O is implemented with the DataInputStream and DataOutputStream classes.
    False
  1158. True or false?  To save objects to a file, the class they belong to must implement the Serializable interface.
    True
  1159. True or false?  A File object represents a file or a directory.
    True
  1160. True or false?  print() is a method of the DataOutputStream class.
    False
  1161. True or false? When reading and writing objects, one cannot save a whole array at once.  One must save the array elements individually.
    False
  1162. True or false?  Primitive type arrays can be cast from one type to another.
    True
  1163. True or false?  The IOException exception exclusively handles the possibility of wrong typecasting in Object I/O.
    False
  1164. True or false?  A text file is a file that must be converted into binary form in order to be compiled by the Java compiler.
    False
  1165. True or false?  In order to ensure that all I/O operations are committed, the close() method should be called on all open streams.
    True
  1166. True or false?  A FileStream object can only take in as an argument a File object.
    False
  1167. True or false?  The goal of data caching is to save space in main memory.
    False
  1168. True or false?  Typecasting chars to bytes or bytes to chars is a difficult task because of the differing bit sizes of each of the data types.
    False
  1169. True or false?  C:JavaProjectsCh11 is a typical Windows filepath.
    True
  1170. True or false?  The accept() method of the FileFilter interface returns a Boolean value.
    True
  1171. True or false?  In Java, one dot (.) represents “one directory above”, while two dots (..) represents “two directories above”.
    False
  1172. True or false?  With text I/O, data are read and saved as strings.
    True
  1173. Which of the following classes is not  used for reading data from a file?

    a. FileInputStream
    b. Scanner
    c. FileReader
    d. None of the above
    d. None of the above
  1174. Streams that input bytes and output bytes to files are known as:

    A) Character-based streams
    B) Byte-based streams
    C) Bit-based streams
    D) Unicode-based streams
    B) Byte-based streams
    (this multiple choice question has been scrambled)
  1175. Which of the following returns the length of a Node List?

    a. length()
    b. length
    c. size()
    d. None of the above
    d. None of the above
  1176. Which of the following can be used to create a Document object?

    a. DocumentBuilderFactory
    b. DocumentBuilder
    c. SAXBuilder
    d. All of the above
    • b. DocumentBuilder
    • c. SAXBuilder
  1177. Which of the following statements is true?

    a) JSON is more efficient than XML.
    b) JDOM is lightweight and is better than the traditional DOM parser of JAVA.
    c) An attribute in JDOM is data typed as Attribute while it is data typed as Node in the traditional DOM parser of JAVA.
    d) All of above are true.
    d) All of above are true.
  1178. True/False: The list() method of the File class returns an array of File objects.
    False
  1179. True/False: FileFilter is an interface that offers only one method called filter and the latter is used to check to see whether a given file should be filtered out.
    False
  1180. True/False: A JSON array is delimited by opening and closing square brackets.
    True
  1181. True/False: To get the JSONObject stored at index i of the JSONArray called itemsList, one can use the following statement:

    JSONObject item = itemsList.get(i);
    False
  1182. True/False: When creating an HTML document, developers must use a set of predefined
    tags.
    True
  1183. True/False:  In the case of method overloading, there must be an IS-A relationship.
    False
  1184. Abstraction hides the ________________.

    a) class
    b) complexity
    b) complexity
  1185. What is the difference between aggregation and composition?

    a) Aggregation represents strong relationship whereas composition represents weak relationship
    b) Aggregation represents weak relationship whereas composition represents strong relationship
    b) Aggregation represents weak relationship whereas composition represents strong relationship
  1186. If there is private method in the class, which type of binding will there be?

    a) static
    b) dynamic
    a) static
  1187. Abstract method can be in ________________.

    a) normal class
    b) abstract class
    b) abstract class
  1188. True/False:  The return type can be the same in method overriding.
    True
  1189. True/False: One of the features of object-based programming languages is inheritance.
    False
  1190. True/False:  Runtime polymorphism can be achieved by data members.
    False
  1191. Name should be started with lowercase letters in the case of ___________________.

    a) interface
    b) method
    b) method
  1192. The input/output package usually used with Java is;

    A) javafile
    B) java.io
    C) java.inout
    D) java.inout
    B) java.io
    (this multiple choice question has been scrambled)
  1193. Can data flow through a given stream in both directions?

    A) Yes; only one stream is needed to read or write.
    B) Yes; but only one direction at a time.
    C) No; a stream has one direction only, input or output.
    D) No; streams only work for output.
    C) No; a stream has one direction only, input or output.
    (this multiple choice question has been scrambled)
  1194. What is the name of the abstract base class for streams dealing with character input?

    A) Reader
    B) Writer
    C) OutputStream
    D) InputStream
    A) Reader
    (this multiple choice question has been scrambled)
  1195. Is the character data used inside a Java program exactly the same format as the character data in a text file written by Java?

    A) No. Internally Java programs always use 16-bit char data; but text files are written in UTF format, which is different.
    B) Yes.  Character data has always used the same format for all computers and all files.
    C) Yes.  Java uses the same format for characters inside a program and in text files.
    D) No.  Internally Java uses 8-bit character data, but text files always use ASCII.
    A) No. Internally Java programs always use 16-bit char data; but text files are written in UTF format, which is different.
    (this multiple choice question has been scrambled)
  1196. A stream that is intended for general purpose IO, not usually character data, is called_____________.

    A) Character Stream
    B) Writer
    C) Byte Stream
    D) Reader
    C) Byte Stream
    (this multiple choice question has been scrambled)
  1197. What is a buffer?

    A) Any stream that deals with character IO.
    B) The cable that connects a dat source to the bus.
    C) A file that contains binary data.
    D) A section of memory used as a staging area for the input or output of data. 
    D) A section of memory used as a staging area for the input or output of data.
    (this multiple choice question has been scrambled)
  1198. Can a stream act as a data source for another stream?

    A) No.  Streams must be connected directly to physical devices.
    B) Yes.  An input stream can be connected to an output stream.
    C) Yes.  Some streams can be connected together.
    B) Yes.  An input stream can be connected to an output stream.
    (this multiple choice question has been scrambled)
  1199. What is the name of a stream that connects two running programs?

    A) program stream
    B) channel
    C) conduit
    D) pipe
    D) pipe
    (this multiple choice question has been scrambled)
  1200. What is a stream that transforms data in some way called?

    A) processing stream
    B) UTF stream
    C) pipe
    D) transformer
    A) processing stream
    (this multiple choice question has been scrambled)
  1201. What is the name of the abstract base class dealing with general purpose (non-character) input?

    A) OutputStream
    B) Reader
    C) InputStream
    D) Writer
    C) InputStream
    (this multiple choice question has been scrambled)
  1202. End-of-line comments that should be ignored by the compiler are denoted using:   

    A) Three forward slashes ( /// ).
    B) Two forward slashes ( // ).  
    C) A slash and a star ( /* ).  
    D) A slash and two stars ( /** ).  
    B) Two forward slashes ( // ).
    (this multiple choice question has been scrambled)
  1203. Which of the following does not cause a syntax error to be reported by the C++ compiler?   

    A) Extra blank lines.  
    B) Missing ; at the end of a statement.  
    C) Mismatched {}.
    D) Missing */ in a comment.  
    A) Extra blank lines.
    (this multiple choice question has been scrambled)
  1204. Which of the following is not a syntax error?  

    a) std::cout << 'Hello world! ';  
    b) std::cout << Hello world!;  
    c) std::cout << "Hello 

                                           world! ";
    d) std::cout << "Hello world! ";
    • c) std::cout << "Hello                                         
    •                
    •                                    world! ";
  1205. The escape sequence for a newline is:   

    A) r  
    B) a
    C) n  
    D) t  
    C) n
    (this multiple choice question has been scrambled)
  1206. Which of the following statements would display the phrase C++ is fun?   

    A) std::cout << '++ is fun';  
    B) std::cout << ""C++ is fun"";
    C) std::cout << C++ is fun;  
    D) std::cout << "Thisis funrC++ ";  
    D) std::cout << "Thisis funrC++ ";
    (this multiple choice question has been scrambled)
  1207. Which of the following is not a valid C++ identifier?   

    A) my Value
    B) m_x  
    C) _AAA1  
    D) width  
    A) my Value
    (this multiple choice question has been scrambled)
  1208. Which is the output of the following statements?

     std::cout << "Hello ";
    std::cout << "World";   

    a) Hello 
        World  
    b) World Hello  
    c) Hello World  
    d) World 
        Hello
    c) Hello World
  1209. Which of the following characters is the escape character?   

    A) "  
    B)
    C) n  
    D) *  
    B)
    (this multiple choice question has been scrambled)
  1210. Which of the following code segments prints a single line containing hello there with the words separated by a single space?   

    a) std::cout << "hello" , " there";   
    b) std::cout << "hello "; 
        std::cout << " there";   
    c) std::cout << "hello"; 
        std::cout << " there";  
    d) std::cout << "hello"; 
        std::cout << "there";
    • c) std::cout << "hello";    
    •     std::cout << " there";
  1211. Which of the following is a variable declaration statement?   

    A) #include
    B) int total;  
    C) // first string entered by user  
    D) int main()  
    B) int total;
    (this multiple choice question has been scrambled)
  1212. A(n) ________ enables a program to read data from the user.   

    A) main declaration. 
    B) return statement.  
    C) std::cin.
    D) std::cout.  
    C) std::cin.
    (this multiple choice question has been scrambled)
  1213. The assignment operator ________ assigns the value of the expression on its right to the variable on its left.   

    A) =.  
    B) <-.
    C) #.  
    D) ->.  
    A) =.
    (this multiple choice question has been scrambled)
  1214. The std::endl stream manipulator:   

    A) terminates the program.  
    B) outputs a newline.  
    C) flushes the output buffer.
    D) outputs a newline and flushes the output buffer.  
    D) outputs a newline and flushes the output buffer.
    (this multiple choice question has been scrambled)
  1215. Which of the following statements does not overwrite a preexisting value stored in a memory location?   

    A) y = y + 2;.  
    B) width = length;.  
    C) int a;.
    D) number = 12;.  
    C) int a;.
    (this multiple choice question has been scrambled)
  1216. Associations in a class diagram that do not have navigability arrows at both ends indicate ___________________.

    A) one-way counterclockwise navigability
    B) bidirectional navigability
    C) no navigability
    D) one-way clockwise navigability
    B) bidirectional navigability
    (this multiple choice question has been scrambled)
  1217. Which of the following statements could potentially change the value of number2?   

    A) std::cin >> number2;  
    B) number1 = number2;  
    C) sum = number1 + number2;  
    D) std::cout << number2;
    A) std::cin >> number2;
    (this multiple choice question has been scrambled)
  1218. What is the value of result after the following C++ statements execute? 

    int a, b, c, d, result;
    a = 4;
    b = 12; c = 37;
    d = 51;
    result = d % a * c + a % b + a;   

    a) 119.  
    b) 51.  
    c) 127.  
    d) 59.
    a) 119.
  1219. List the following operators in the order that they will be evaluated:
    -, *, /, +, %.
    Assume that if two operations have the same precedence, the one listed first will be evaluated first.   

    A) -, +, %, *, /.
    B) +, -, /, *, %
    C)  *, /, %, -, +.  
    D) -, *, %, +, /.  
    C)  *, /, %, -, +.
    (this multiple choice question has been scrambled)
  1220. Which of the following is not an arithmetic operator?  

    A) +
    B) -  
    C) =
    D) %  
    C) =
    (this multiple choice question has been scrambled)
  1221. Which of the following is not an actor of the ATM system?

    A) A user who deposits funds into the ATM
    B) A user who withdraws cash from the ATM
    C) A user who provides requirements for building the ATM system
    D) A user who views an account balance
    C) A user who provides requirements for building the ATM system
    (this multiple choice question has been scrambled)
  1222. What will be the output after the following C++ statements have been executed? 

    int a, b, c, d;
         a = 4;
         b = 12;
         c = 37;
         d = 51;

         if ( a < b )
         cout << "a < b";

         if ( a > b )
         cout << "a > b";

          if ( d <= c )
          cout << "d <= c";

          if ( c != d )
          cout << "c != d";
       

    a) a > b 
        c != d  
    b) a < b
        c < d
        a != b  
    c) a < b
        d <= c
        c != d   
    d) a < b
        c != d
    • d) a < b   
    •     c != d
  1223. Which of the following is never a compilation error?   

    A) Using a single equals sign instead of a double equals sign in the condition of an if statement.  
    B) Omitting the left and right parentheses for the condition of an if statement.  
    C) Placing a semicolon at the end of the first line of an if statement.  
    D) Neglecting to declare a local variable in a function before it is used.
    C) Placing a semicolon at the end of the first line of an if statement.
    (this multiple choice question has been scrambled)
  1224. Which of the following statements is false?

    A) Exception handling can resolve exceptions.
    B) Exception handling enable programmers to write robust and fault-tolerant programs. 
    C) Exception handling can catch but not resolve exceptions.
    d) All of the above are true.
    C) Exception handling can catch but not resolve exceptions.
    (this multiple choice question has been scrambled)
  1225. Each of the following is a relational or equality operator except:   

    A) =!  
    B) ==  
    C) <=
    D) >  
    A) =!
    (this multiple choice question has been scrambled)
  1226. The use case diagram models ________.   

    A) the interactions between a system’s client and the system.
    B) each software life cycle by repeating one or more stages several times via use cases.  
    C) each software life cycle stage in succession.  
    D) the interactions between implementations and testing.  
    A) the interactions between a system’s client and the system.
    (this multiple choice question has been scrambled)
  1227. Which of the following is not an actor of the ATM system?   

    A) A user who withdraws cash from the ATM.  
    B) A user who provides requirements for building the ATM system.  
    C) A user who views an account balance.
    D) A user who deposits funds into the ATM.  
    B) A user who provides requirements for building the ATM system.
    (this multiple choice question has been scrambled)
  1228. Which diagram models system structure?   

    A) Activity diagram.  
    B) Class diagram.  
    C) Sequence diagram.
    D) State machine diagram.  
    B) Class diagram.
    (this multiple choice question has been scrambled)
  1229. Which diagram is also called a collaboration diagram?   

    A) Activity diagram.  
    B) Communication diagram.  
    C) Sequence diagram.
    D) State machine diagram.  
    B) Communication diagram.
    (this multiple choice question has been scrambled)
  1230. Why are layers important in subsystem design? Choose all options that apply.  

    a) They make it easier to change the implementation.  
    b) They reduce the number of classes in the implementation.  
    c) They increase reuse.  
    d) They reduce complexity.
    • a) They make it easier to change the implementation.  
    • c) They increase reuse.  
    • d) They reduce complexity.
  1231. In a UML class diagram, how are objects distinguished from classes? Choose only one option.

    A) Object labels are underlined.
    B) Object labels are shown in italics.  
    C) Class labels have a box drawn around them.  
    A) Object labels are underlined.
    (this multiple choice question has been scrambled)
  1232. Currently, what is the most common type of database management system? Choose only one option.  

    A) Network  
    B) Object-oriented.  
    C) Relational.  
    D) Hierarchical.  
    E) Indexed file.
    C) Relational.
    (this multiple choice question has been scrambled)
  1233. What are some of the advantages of Java as an implementation technology? Choose all options that apply.  

    a) Object-oriented purity.  
    b) Invented by Microsoft.  
    c) Network readiness.  
    d) Portability.  
    e) Scalability.  
    f)  Security.
    • a) Object-oriented purity.  
    • c) Network readiness.  
    • d) Portability.  
    • e) Scalability.  
    • f)  Security.
  1234. What can an object-oriented type system be used for? Choose all options that apply.  

    a) Improving runtime performance.  
    b) Preventing misuse of a class.  
    c) Avoiding spelling mistakes.  
    d) Making sure that all messages invoke a concrete method.  
    e) Documentation.
    • a) Improving runtime performance.  
    • b) Preventing misuse of a class.  
    • c) Avoiding spelling mistakes.  
    • d) Making sure that all messages invoke a concrete method.  
    • e) Documentation.
  1235. Why is the ability to redefine a method important in object-oriented programming? Choose all options that apply.  

    a) Because it allows us to add extra work to a method.  
    b) Because it allows us to introduce abstract methods that are redefined as concrete methods.  
    c) Because it allows us to provide a more accurate or faster definition in a subclass.  
    d) Because it allows us to disable a method in a subclass.  
    e) Because it allows us to change the meaning of a method.
    • a) Because it allows us to add extra work to a method.  
    • b) Because it allows us to introduce abstract methods that are redefined as concrete methods.  
    • c) Because it allows us to provide a more accurate or faster definition in a subclass.
  1236. Which of the following statements about multiple inheritance are true? Choose all options that apply.  

    a) It offers more modelling choices.  
    b) It makes it more difficult to write compilers and fast runtime systems.  
    c) It simplifies inheritance hierarchies.  
    d) It solves the problem of repeated inheritance.
    • a) It offers more modelling choices.  
    • b) It makes it more difficult to write compilers and fast runtime systems.
  1237. If two customers, on opposite sides of the world, wish to purchase the last ticket available for a concert, what would be a good approach for allocating the ticket? Choose only one option.  

    A) Make the customers take part in a software "race" to get the ticket.  
    B) Don't allow the last ticket to be sold, because that would be unfair to one of the customers.
    C) Introduce an extra business rule that combines a query for ticket availability with a temporary reservation.  
    C) Introduce an extra business rule that combines a query for ticket availability with a temporary reservation.
    (this multiple choice question has been scrambled)
  1238. What is meant by the term "design by fear"? Choose only one option.  

    A) You design a system too quickly because of time pressures.
    B) You cannot know when to trust the code.  
    C) Design is scary.  
    B) You cannot know when to trust the code.
    (this multiple choice question has been scrambled)
  1239. What is meant by "object identity"? Choose only one option.  

    A) All objects are the same as each other.  
    B) Every object has a unique identity that distinguishes it from all other objects.
    C) Every object's class has a unique serial number. 
    D) Two objects are identical if their attributes have the same value. 
    B) Every object has a unique identity that distinguishes it from all other objects.
    (this multiple choice question has been scrambled)
  1240. Which of the following UML artifacts are used to show the distribution of processes, artifacts and model elements in a system? Choose only one option.  

    A) State machine diagrams.  
    B) Glossaries.
    C) Communication diagrams.  
    D) Deployment diagrams.  
    E) Class Diagrams.  
    F) Sequence diagrams.  
    G) Interaction diagrams.  
    D) Deployment diagrams.
    (this multiple choice question has been scrambled)
  1241. Which of the following terms best describes an object that is made up of other objects? Choose only one option.  

    A) Generalization.  
    B) Inheritance.  
    C) Specialization.
    D) Aggregation.  
    E) Association.  
    D) Aggregation.
    (this multiple choice question has been scrambled)
  1242. Which of the following statements are true? Choose all options that apply.  

    a) Most superclasses are abstract.  
    b) Inheritance is preferable to composition.  
    c) Most superclasses are concrete.  
    d) Composition is preferable to inheritance.
    • a) Most superclasses are abstract. 
    • d) Composition is preferable to inheritance.
  1243. In UML diagrams, how are abstract classes distinguished from concrete classes? Choose only one option.  

    A) Labels on concrete classes are shown in italics.  
    B) Concrete classes are shown as boxes with dashed outlines.  
    C) Abstract classes are shown as boxes with dashed outlines.
    D) Labels on abstract classes are shown in italics.  
    D) Labels on abstract classes are shown in italics.
    (this multiple choice question has been scrambled)
  1244. What is "design by contract"? Choose only one option.  

    A) Designing code as if there were a contract between an object that sends a message and the object that receives it.  
    B) Designing a software system under contract.
    C) Reinforcing the contract between every pair of objects by increasing the amount of error-checking.  
    D) Protecting your software using a contract with a firewall.  
    A) Designing code as if there were a contract between an object that sends a message and the object that receives it.
    (this multiple choice question has been scrambled)
  1245. What does the term "polymorphism" refer to? Choose all options that apply.  

    a) The ability of a variable to point at different classes of object at different times.  
    b) The fact that a message with the same signature can invoke different methods at different times.  
    c) All object-oriented programming languages are different.  
    d) All object-oriented methodologies use a different notation.
    • a) The ability of a variable to point at different classes of object at different times.  
    • b) The fact that a message with the same signature can invoke different methods at different times.
  1246. In UML diagrams, how are classmessages distinguished from instance messages? Choose only one option.  

    A) Class messages are underlined.  
    B) Class messages are shown in brackets.  
    C) Class messages are shown in italics.  
    D) Class messages are shown with the keyword <<static>>.
    A) Class messages are underlined.
    (this multiple choice question has been scrambled)
  1247. What is a "generic" class? Choose only one option.  

    A) A class that has other classes as parameters.
    B) A class that represents all objects.  
    C) A class with no declared copyright.  
    A) A class that has other classes as parameters.
    (this multiple choice question has been scrambled)
  1248. What is an "abstract" class? Choose only one option.  

    A) An object.  
    B) A class with at least one undefined message.  
    C) A class with no concrete subclasses.  
    D) An interface.
    E) A class with no methods.  
    B) A class with at least one undefined message.
    (this multiple choice question has been scrambled)
  1249. What are the traditional steps in software production? Choose all options that apply.  

    a) Maintenance.  
    b) Design.  
    c) Iteration.  
    d) Incrementation.  
    e) Deployment.  
    f) Analysis.  
    g) Requirements capture.  
    h) Testing.  
    i) Reuse.  
    j) Implementation. 
    k) Specification.
    • a) Maintenance.  
    • b) Design.  
    • e) Deployment.  
    • f) Analysis.  
    • g) Requirements capture.  
    • h) Testing. 
    • j) Implementation. 
    • k) Specification.
  1250. What is "encapsulation"? Choose only one option.  

    A) Depicting objects using state machine diagrams.  
    B) Ensuring that the data inside an object can only be accessed via operations.  
    C) Sealing the state of an object so that it cannot be changed.  
    D) Putting objects into a collection.
    B) Ensuring that the data inside an object can only be accessed via operations.
    (this multiple choice question has been scrambled)
  1251. In UML, which diagrams are used to show messages sent between objects? Choose all options that apply.  

    a) Activity diagrams.  
    b) Object diagrams.  
    c) Communication diagrams.  
    d) State machine diagrams.  
    e) Sequence diagrams.  
    f) Deployment diagrams.
    • c) Communication diagrams.
    • e) Sequence diagrams.
  1252. What is meant by the term "deadlock"? Choose only one option.  

    A) An object is waiting for a resource, which is being used by an object waiting for a resource used by the first object.
    B) An object's monitor allows its lock to terminate early.  
    C) Two processes or threads refuse to talk to each other.  
    A) An object is waiting for a resource, which is being used by an object waiting for a resource used by the first object.
    (this multiple choice question has been scrambled)
  1253. Servlets are a direct replacement for what? Choose only one option.  

    A) CORBA.
    B) XML.  
    C) ActiveX controls.  
    D) CGI scripts.  
    E) Applets.  
    D) CGI scripts.
    (this multiple choice question has been scrambled)
  1254. Which of the following UML artifacts is used to show the steps involved in getting value from a system? Choose only one option. 

    A) Class diagrams.  
    B) Deployment diagrams.
    C) State machine diagrams.  
    D) Use cases.  
    E) Glossaries.  
    F)  User interface sketches.  
    D) Use cases.
    (this multiple choice question has been scrambled)
  1255. What is an association class? Choose only one option.  

    A) It adds attributes and/or behaviour to an association between two other classes.  
    B) It describes the various kinds of relationship that can exist between classes.  
    C) It associates an object with the class of which it is an instance.
    A) It adds attributes and/or behaviour to an association between two other classes.
    (this multiple choice question has been scrambled)
  1256. Which of the following terms best describes the case where a Stack class is implemented using an internal instance of List? Choose only one option.  

    A) Association.  
    B) Specialization.  
    C) Singularity.
    D) Composition.  
    E) Genericity.  
    D) Composition.
    (this multiple choice question has been scrambled)
  1257. What is a "thread"? Choose only one option.  

    A) A designer's thought process.
    B) An independent process running on a node, with its own memory and IO.  
    C) An activity within a process that shares memory with other activities.  
    C) An activity within a process that shares memory with other activities.
    (this multiple choice question has been scrambled)
  1258. All of the following are true about classes, except:   

    A) The first class in any C++ program is main.
    B) Classes have attributes and behaviors.  
    C) An object must be created from a class before it can be used.  
    D) A class’s functions hide from the user the complex tasks they perform.  
    A) The first class in any C++ program is main.
    (this multiple choice question has been scrambled)
  1259. C++ functions other than main are executed:   

    A) Never.  
    B) Before main executes.  
    C) When they are explicitly called by another function.
    D) After main completes execution.  
    C) When they are explicitly called by another function.
    (this multiple choice question has been scrambled)
  1260. Function headers contain all of the following except:    

    A) Return type.  
    B) Left brace.  
    C) Parentheses.  
    D) Name of function.
    B) Left brace.
    (this multiple choice question has been scrambled)
  1261. An object creation expression contains:    

    A) Parentheses.  
    B) All of the above.  
    C) The name of the class.  
    D) The name of the object.
    B) All of the above.
    (this multiple choice question has been scrambled)
  1262. Calling a member function of an object requires which item?   

    a) The dot separator.  
    b) Open and close braces.  
    c) None of the above.  
    d) The class name.
    a) The dot separator.
  1263. In the UML, the top compartment of the rectangle modeling a class contains:    

    a) The class’s name.  
    b) All of the above.  
    c) The class’s behaviors.  
    d) The class’s attributes.
    a) The class’s name.
  1264. What is the name of the values the method call passes to the method for the parameters?   

    A) References.  
    B) Values.  
    C) Objects.  
    D) Arguments.
    D) Arguments.
    (this multiple choice question has been scrambled)
  1265. Assuming that text is a variable of type string, what will be the contents of text after the statement cin >> text; is executed if the user types “Hello World!” and then presses Enter?

    A)  Hello World! 
    B)  Hello World
    C)  H 
    D)  Hello 
    D)  Hello
    (this multiple choice question has been scrambled)
  1266. Multiple parameters are separated by what symbol?   

    A) Parentheses. 
    B) The dot separator. 
    C) Braces. 
    D) Commas.
    D) Commas.
    (this multiple choice question has been scrambled)
  1267. Attributes of a class are also known as:   

    A) Local variables.
    B) Classes. 
    C) Constructors.
    D) Data members. 
    D) Data members.
    (this multiple choice question has been scrambled)
  1268. What is the default initial value of a String in C++?   

    A) ""
    B) "default" 
    C) null 
    D) default 
    A) ""
    (this multiple choice question has been scrambled)
  1269. What type of member functions allow a client of a class to assign values to private data members?  

    A) Set member functions. 
    B) Client member functions.
    C) Assign member functions. 
    D) Access member functions.
    A) Set member functions.
    (this multiple choice question has been scrambled)
  1270. A default constructor has how many parameters?  

    A) 1. 
    B) 0. 
    C) Variable.
    D) 2. 
    B) 0.
    (this multiple choice question has been scrambled)
  1271. A constructor can specify the return type:   

    A) void. 
    B) int. 
    C) string.
    D) A constructor cannot specify a return type.  
    D) A constructor cannot specify a return type.
    (this multiple choice question has been scrambled)
  1272. The compiler will implicitly create a default constructor if:  

    A) The programmer specifically requests that the compiler do so. 
    B) The class does not define any constructors.  
    C) The class does not contain any data members.
    D) The class already defines a default constructor. 
    B) The class does not define any constructors.
    (this multiple choice question has been scrambled)
  1273. A header file is typically given the filename extension: 

    A)  .h.
    B)  .hdr.
    C)  .header.
    D)  .cpp.
    A)  .h.
    (this multiple choice question has been scrambled)
  1274. Assuming that GradeBook.h is found in the current directory and the iostream header file is found in the C++ Standard Library header file directory, which of the following preprocessor directives will fail to find its desired header file?  

    a) #include "iostream". 
    b) #include .  
    c) #include "GradeBook.h". 
    d) #include .
    • d) #include .  OR
    • b) #include .  

    (Typo somewhere in the original print of this question.)
  1275. In the source-code file containing a class’s member function definitions, each member function definition must be tied to the class definition by preceding the member function name with the class name and ::, which is known as the:  

    A) Class implementation connector.
    B) Source code resolver. 
    C) Binary scope resolution operator. 
    D) Member definition linker. 
    C) Binary scope resolution operator.
    (this multiple choice question has been scrambled)
  1276. When compiling a class’s source code file (which does not contain a main function), the information in the class’s header file is used for all of the following, except:  

    a) Ensuring that each member function knows about the class’s data members and other member functions. 
    b) Determining the correct amount of memory to allocate for each object of the class. 
    c) All of the above are uses that the compiler has for the header file information. 
    d) Ensuring that the first line of each member function matches its prototype.
    b) Determining the correct amount of memory to allocate for each object of the class.
  1277. When a client code programmer uses a class whose implementation is in a separate file from its interface, that implementation code is merged with the client’s code during the:   

    A) Programming phase. 
    B) Linking phase. 
    C) Compiling phase. 
    D) Executing phase.
    B) Linking phase.
    (this multiple choice question has been scrambled)
  1278. To execute multiple statements when an if statement’s condition is true, enclose those statements in a pair of:  

    A) Braces, { }.
    B) Angle brackets, < >. 
    C) Square Brackets, [ ]. 
    D) Parentheses, ( ). 
    A) Braces, { }.
    (this multiple choice question has been scrambled)
  1279. Assuming that the string object text contains the string “Hello!!!”, the expression text.substr( 2 , 5 ) would return a string object containing the string: 

    A)  “ello!”. 
    B)  “llo!”.
    C)  “llo!!”. 
    D)  “ello”. 
    C)  “llo!!”.
    (this multiple choice question has been scrambled)
  1280. A solid line representing an association between two classes can be accompanied by any of the following details, except:  

    A) An aggregation relationship with another association line. 
    B) A number near the end of each line indicating multiplicity values.
    C) A role name for one or both of the objects.  
    D) A name and direction for the association. 
    A) An aggregation relationship with another association line.
    (this multiple choice question has been scrambled)
  1281. A composition or “has-a” relationship is represented in the UML by:  

    A) Making the association line dashed
    B) Making the association line bolded.  
    C) Attaching a solid triangle to the association line. 
    D) Attaching a solid diamond to the association line. 
    D) Attaching a solid diamond to the association line.
    (this multiple choice question has been scrambled)
  1282. Specifying the order in which statements are to be executed in a computer program is called:   

    A) An algorithm. 
    B) Program control.
    C) Pseudocode. 
    D) Transfer of control. 
    B) Program control.
    (this multiple choice question has been scrambled)
  1283. Which of the following is true of a pseudocode program?  

    A) They are executed by the computer. 
    B) They help the programmer “think out” a program. 
    C) All of the above are false. 
    D) They include declarations and all types of statements.
    B) They help the programmer “think out” a program.
    (this multiple choice question has been scrambled)
  1284. Pseudocode does not include:  

    A) Algorithms. 
    B) Input/output. 
    C) Declarations.
    D) Control structures. 
    C) Declarations.
    (this multiple choice question has been scrambled)
  1285. Which of the following encompasses the other three?  

    A) Repetition structure. 
    B) Control structure. 
    C) Sequence structure. 
    D) Selection structure.
    B) Control structure.
    (this multiple choice question has been scrambled)
  1286. In an activity diagram for an algorithm, what does a solid circle surrounded by a hollow circle represent?   

    A) Transition.
    B) Final state. 
    C) Action state. 
    D) Initial state. 
    B) Final state.
    (this multiple choice question has been scrambled)
  1287. Which of the following is a double-selection statement?  

    A)  if…else. 
    B)  do…while.
    C)  switch. 
    D)  if. 
    A)  if…else.
    (this multiple choice question has been scrambled)
  1288. Which of the following is a repetition structure?    

    A) if. 
    B) switch. 
    C) do…while.
    D) if…else.
    C) do…while.
    (this multiple choice question has been scrambled)
  1289. If grade has the value of 60, what will the following code print? 

    If ( grade >= 60 )
          Cout << "Passed";
     

    A)  cout << "Passed";. 
    B)  nothing. 
    C)  c. Passed.
    D)  60. 
    C)  c. Passed.
    (this multiple choice question has been scrambled)
  1290. The data type bool:  

    A) Can take on any expression as a value.  
    B) Can take on values -1, 0 or 1. 
    C) Can take on values true and false.
    D) Can only be used in a selection statement.  
    C) Can take on values true and false.
    (this multiple choice question has been scrambled)
  1291. The conditional operator (?:):  

    A) Is the only ternary operator in C++. 
    B) Accepts two operands.
    C) Is a unary operator. 
    D) Associates from left to right. 
    A) Is the only ternary operator in C++.
    (this multiple choice question has been scrambled)
  1292. Which of the following does not perform the following task: print correct if answer is equal to 7 and incorrect if answer is not equal to 7?  

    a) If ( answer == 7 )
          cout << "correct";
        else
          cout << "incorrect";
    b) answer == 7 ? cout << "correct" : cout << "incorrect"; 
    c) cout << ( answer == 7 ? "correct" : "incorrect" ); 
    d) cout << answer == 7 ? "correct" : "incorrect";
    c) cout << ( answer == 7 ? "correct" : "incorrect" ); 

    or  

    d) cout << answer == 7 ? "correct" : "incorrect";

    Somewhere there is a typo in the original publication of this question example.
  1293. A block:  

    A) Is represented by placing a semicolon (;) where a statement would normally be.
    B) Cannot contain declarations. 
    C) Is a compound statement. 
    D) Must contain exactly three statements. 
    C) Is a compound statement.
    (this multiple choice question has been scrambled)
  1294. What is wrong with the following while loop? 

    while ( sum <= 1000 )
    sum = sum – 30;

    A) Braces are required around sum = sum – 30;.
    B) There should be a semicolon after while ( sum <= 1000 ). 
    C) The parentheses should be braces. 
    D) sum = sum – 30 should be sum = sum + 30 or else the loop may never end.  
    D) sum = sum – 30 should be sum = sum + 30 or else the loop may never end.
    (this multiple choice question has been scrambled)
  1295. How many times will the following loop print hello? 

    i = 1;
    while ( i <= 10 )
               cout << "hello";
      
    A)  0.
    B)  9.  
    C)  An infinite number of times. 
    D)  10.
    C)  An infinite number of times.
    (this multiple choice question has been scrambled)
  1296. An uninitialized local variable contains:  

    A) A value of zero. 
    B) The value last stored in the memory location reserved for that variable. 
    C) A randomly assigned value.
    D) No value.
    B) The value last stored in the memory location reserved for that variable.
    (this multiple choice question has been scrambled)
  1297. Using a loop’s counter-control variable in a calculation after the loop ends often causes a common logic error called:  

    A) A fatal logic error.
    B) A counter exception. 
    C) An off-by-one error. 
    D) A syntax error. 
    C) An off-by-one error.
    (this multiple choice question has been scrambled)
  1298. Indefinite repetition is controlled by a:   

    A) Sentinel value. 
    B) Absence of a condition.
    C) Non-constant condition. 
    D) Counter. 
    A) Sentinel value.
    (this multiple choice question has been scrambled)
  1299. A fatal logic error can be caused by:  

    A) Using a counter variable in a calculation after the loop. 
    B) Choosing a sentinel value that is also a data value. 
    C) An attempt to divide by zero. 
    D) Not initializing variables before executing a repetition structure.
    C) An attempt to divide by zero.
    (this multiple choice question has been scrambled)
  1300. In indefinite repetition, an input value:  

    A) Can be entered, processed, and evaluated in any order. 
    B) Should always be evaluated before being processed.
    C) Should always be processed directly after it is entered. 
    D) Should never be modified. 
    B) Should always be evaluated before being processed.
    (this multiple choice question has been scrambled)
  1301. What is the final value of x after performing the following operations? 

    int x = 21;
    double y = 6;
    double z = 14;
    y = x / z;
    x = 5.5 * y;
     
    A)  5.5. 
    B)  8. 
    C)  8.25.
    D)  5. 
    B)  8.
    (this multiple choice question has been scrambled)
  1302. Which operation does not take place in the following example?

    int x = 21;
    double y = 6;
    double z = 14;
    y = x / z;
    x = 5.5 * y;
      
    A) Truncation. 
    B) Explicit conversion.
    C) Promotion.  
    D) Implicit conversion. 
    D) Implicit conversion.
    (this multiple choice question has been scrambled)
  1303. Having a loop within a loop is known as:   

    A) Recursive.
    B) Nesting. 
    C) Doubling up. 
    D) A redundancy. 
    B) Nesting.
    (this multiple choice question has been scrambled)
  1304. To handle situations where a loop must reinitialize a variable at the beginning of each iteration, such reinitialization could be performed by:  

    A) An assignment statement before the loop body.
    B) An assignment statement after the loop body. 
    C) A declaration inside the loop body. 
    D) A declaration after the loop body. 
    C) A declaration inside the loop body.
    (this multiple choice question has been scrambled)
  1305. If x initially contains the value 3, which of the following sets x to 7? 

    A) x += 4;
    B) x =+ 4; 
    C) x ++ 4;
    D) x + 4 = x;
    A) x += 4;
    (this multiple choice question has been scrambled)
  1306. Assuming that x and y are equal to 3 and 2, respectively, after the statement x -= y executes, the values of x and y will be: 

    A)  x: 1; y: 2. 
    B)  x: 3; y: -1. 
    C)  x: 5; y: 3.
    D)  x: 3; y: 5. 
    A)  x: 1; y: 2.
    (this multiple choice question has been scrambled)
  1307. Which of the following will not increment c by 1?   

    A) ++c;.
    B)  c + 1;. 
    C) c++;. 
    D) c += 1;. 
    B)  c + 1;.
    (this multiple choice question has been scrambled)
  1308. Assuming that x is equal to 4, which of the following statements will not result in y containing the value 5 after execution?  

    A) d. y = x + 1. 
    B) y = x++;. 
    C) y = 5;. 
    D) y = ++x;.
    B) y = x++;.
    (this multiple choice question has been scrambled)
  1309. Which of the following operations has the highest precedence?  

    A) Assignment. 
    B) Addition. 
    C) Postincrement. 
    D) Multiplication.
    C) Postincrement.
    (this multiple choice question has been scrambled)
  1310. Which of the following is not a piece of information that could be found in the attribute compartment of a class’s rectangle in the UML?  

    A) The attribute’s name. 
    B) The attribute’s initial value.
    C) The attribute’s memory location. 
    D) The attribute’s type. 
    C) The attribute’s memory location.
    (this multiple choice question has been scrambled)
  1311. A class-type attribute is best modeled by: 

    A) Breaking the class down into its fundamental-type components.
    B)  A composition association. 
    C)  An inheritance association. 
    D)  Encapsulating both classes in a third, larger class. 
    B)  A composition association.
    (this multiple choice question has been scrambled)
  1312. Which of the following does counter-controlled repetition require?  

    A) An increment or decrement by which the control variable is modified each time through the loop. 
    B) An initial value.
    C) A condition that tests for the final value.
    D) Counter-controlled repetition requires all of these mentioned. 
    D) Counter-controlled repetition requires all of these mentioned.
    (this multiple choice question has been scrambled)
  1313. The statement;

    while ( --counter >= 1 )
    counter % 2 ? cout << "A" : cout << "B";

    cannot be rewritten as:

    a)  while ( --counter >= 1 )
    counter % 2 == 0 ? cout << "B" : cout << "A";.

    b)  while ( counter > 1 )
    {
    --counter;

    if ( counter % 2 )
    cout << "A";
    else
    cout << "B";
    }.
     
    c)  while ( counter >= 1 )
    if ( counter % 2 )
    cout << "A";
    else
    cout << "B";
    --counter;

    d)  while ( --counter >= 1 )
    if ( counter % 2 )
    cout << "A";
    else
    cout << "B";.
    • c)  while ( counter >= 1 )
    • if ( counter % 2 )
    • cout << "A";
    • else
    • cout << "B";
    • --counter;
  1314. Which of the following is a bad programming practice? 

    a) Indenting the statements in the body of each control structure. 
    b) Placing vertical spacing above and below control structures. 
    c) Using floating-point values for counters in counter-controlled repetition. 
    d) Nesting multiple repetition structures one within another.
    c) Using floating-point values for counters in counter-controlled repetition.
  1315. If a variable is declared in the initialization expression of a for structure, then:  

    A) It retains its final value after the loop is finished. 
    B) It is automatically reinitialized to zero once the loop is finished. 
    C) It can not be used in any structures that are nested in that for structure. 
    D) The scope of the variable is restricted to that particular for loop.
    D) The scope of the variable is restricted to that particular for loop.
    (this multiple choice question has been scrambled)
  1316. Which of the following is not true?  

    A) You must declare the control variable outside of the for loop. 
    B) A for loop can always be used to replace a while loop, and vice versa.
    C) The initialization and increment expressions can be comma-separated lists.  
    D) The three expressions in the for structure are optional. 
    A) You must declare the control variable outside of the for loop.
    (this multiple choice question has been scrambled)
  1317. Consider the execution of the following for loop;

    for (int x = 1; x < 5; increment )
    cout << x + 1 << endl;

    If the last value printed is 5, which of the following might have been used for increment?  

    A) x += 1.
    B) a. x++. 
    C) Any of these mentioned. 
    D) ++x. 
    C) Any of these mentioned.
    (this multiple choice question has been scrambled)
  1318. Which of the following for headers is not valid?  

    A) for ( int i = 0; i < 10; i++ ). 
    B) for ( int i = 0; int j = 5; ; i++ ). 
    C) int i = 0; for ( ; i < 10; i++ ).
    D) for ( int i = 0: i < 10; ). 
    B) for ( int i = 0; int j = 5; ; i++ ).
    (this multiple choice question has been scrambled)
  1319. float and double variables should be used:  

    A) As counters.
    B) To store true/false values. 
    C) To perform monetary calculations. 
    D) As imprecise representations of decimal numbers. 
    D) As imprecise representations of decimal numbers.
    (this multiple choice question has been scrambled)
  1320. Which of the following is a parameterized stream manipulator used to format output?    

    A) left. 
    B) right. 
    C) fixed.
    D) setw. 
    D) setw.
    (this multiple choice question has been scrambled)
  1321. If a do…while structure is used:  

    A) Counter-controlled repetition is not possible. 
    B) An infinite loop will not take place.
    C) An off-by-one error will not occur. 
    D) The body of the loop will execute at least once.  
    D) The body of the loop will execute at least once.
    (this multiple choice question has been scrambled)
  1322. What will the following program segment do?

    int counter = 1;
    do {
         cout << counter << " ";
    } while ( ++counter <= 10 );
      
    A) Cause a syntax error.
    B) Print the numbers 1 through 9. 
    C) Print the numbers 1 through 11. 
    D) Print the numbers 1 through 10. 
    D) Print the numbers 1 through 10.
    (this multiple choice question has been scrambled)
  1323. A switch statement should be used:  

    A) To replace all if and if…else statements. 
    B) As a single-selection structure. 
    C) As a multiple-selection structure.
    D) As a double-selection structure.  
    C) As a multiple-selection structure.
    (this multiple choice question has been scrambled)
  1324. In a switch structure:  

    A) A break is required after the default case.  
    B) A default case is required.
    C) A break is required after each case. 
    D) Multiple actions do not need to be enclosed in braces. 
    D) Multiple actions do not need to be enclosed in braces.
    (this multiple choice question has been scrambled)
  1325. Which of the following is correct when labeling cases in a switch structure?  

    A) case 1. 
    B) Case1. 
    C) case1. 
    D) Case 1.
    A) case 1.
    (this multiple choice question has been scrambled)
  1326. switch can be used to test:  

    A) string constants. 
    B) all types of constants. 
    C) int constants.
    D) float constants. 
    C) int constants.
    (this multiple choice question has been scrambled)
  1327. Which of the following data types can be used to represent integers?  

    A) long.
    B) short. 
    C) All of these mentioned. 
    D) char. 
    C) All of these mentioned.
    (this multiple choice question has been scrambled)
  1328. Which of the following is false?  

    A) break statements exit from the loop in which they are embedded. 
    B) break and continue statements alter the flow of control. 
    C) continue and break statements may be embedded within all C++ structures.
    D) continue statements skip the remaining statements in current iteration of the body of the loop in which they are embedded.  
    C) continue and break statements may be embedded within all C++ structures.
    (this multiple choice question has been scrambled)
  1329. Which of the following is false?  

    A) You should always try to write the fastest, smallest code possible before attempting to make it simple and correct. 
    B) break and continue statements can perform faster than their corresponding structured techniques. 
    C) The effects of break and continue statements can be achieved by structured programming techniques. 
    D) Many programmers feel that break and continue violate structured programming.
    A) You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.
    (this multiple choice question has been scrambled)
  1330. In C++, the condition ( 4 > y > 1 ):  

    A) Evaluates correctly and could be replaced by ( 4 > y && y > 1 ).
    B) Does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ). 
    C) Does not evaluate correctly and should not be replaced by ( 4 > y && y > 1 ). 
    D) Evaluates correctly and could not be replaced by ( 4 > y && y > 1 ). 
    B) Does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ).
    (this multiple choice question has been scrambled)
  1331. The OR (||) operator:  

    A) Has higher precedence than the AND (&&) operator. 
    B) Associates from right to left. 
    C) Stops evaluation upon finding one condition to be true. 
    D) Is a ternary operator.
    C) Stops evaluation upon finding one condition to be true.
    (this multiple choice question has been scrambled)
  1332. An operator that associates from right to left is:   

    A) ().
    B) !=. 
    C) ,. 
    D) ?:. 
    D) ?:.
    (this multiple choice question has been scrambled)
  1333. The expression if ( num != 65 ) cannot be replaced by:  

    A) if ( num > 65 || num < 65 ). 
    B) if ( !( num – 65 ) ).
    C) if ( num – 65 ). 
    D) if ( !( num == 65 ) ). 
    B) if ( !( num – 65 ) ).
    (this multiple choice question has been scrambled)
  1334. An example of a unary operator is:  

    A) The ! logical operator.
    B) The = assignment operator. 
    C) The < relational operator. 
    D) The % arithmetic operator.  
    A) The ! logical operator.
    (this multiple choice question has been scrambled)
  1335. Variables are also known as:  

    A) rvalues, and cannot be used as lvalues.  
    B) lvalues, but can be used as rvalues.
    C) lvalues, and cannot be used as rvalues.  
    D) Constant variables. 
    B) lvalues, but can be used as rvalues.
    (this multiple choice question has been scrambled)
  1336. Consider the following code, assuming that x is an int with an initial value of 12;

    if( x = 6 )
    cout << x;

    What is the output?  

    A) Nothing. 
    B) A syntax error is produced. 
    C) 6.
    D) 12. 
    C) 6.
    (this multiple choice question has been scrambled)
  1337. Of the following, which is not a logic error?   

    A) Failing to initialize counter and total variables before the body of a loop. 
    B) Using == to assign a value to a variable.
    C) Not placing curly braces around the body of an if that contains two statements. 
    D) Using commas instead of the two required semicolons in a for header. 
    D) Using commas instead of the two required semicolons in a for header.
    (this multiple choice question has been scrambled)
  1338. The ____________, __________ and ____________ are the only three forms of control necessary.  

    A) sequence, selection, repetition. 
    B) break, continue, if…else. 
    C) switch, if, else.
    D) for, while, do…while. 
    A) sequence, selection, repetition.
    (this multiple choice question has been scrambled)
  1339. Which of the following is not one of the C++ control structures?   

    A) main. 
    B) switch.
    C) if. 
    D) do…while. 
    A) main.
    (this multiple choice question has been scrambled)
  1340. Which of the following is not one the rules for forming structured programs?  

    A) Any action state can be replaced by two action states in sequence  
    B) Any transition arrow can be reversed.
    C) Any action state can be replaced by any control statement. 
    D) Begin with the “simplest activity diagram.”  
    B) Any transition arrow can be reversed.
    (this multiple choice question has been scrambled)
  1341. Which of the following is not a part of a UML state diagram?  

    A) A solid circle indicating the initial state.  
    B) Arrows with accompanying event description text representing transitions.  
    C) Rounded rectangles representing states.
    D) Fractions beside each state indicating the likelihood of entering that state. 
    D) Fractions beside each state indicating the likelihood of entering that state.
    (this multiple choice question has been scrambled)
  1342. An activity diagram for modeling the actions involved in executing a balance inquiry transaction using the BalanceInquiry object should not include:  

    A) Receiving the user’s main menu input indicating a desire to inquire the amount of his or her balance. 
    B) Displaying the user’s balance information on the screen. 
    C) All of these mentioned should be modeled in this activity diagram.
    D) Retrieving the user’s balance information from the database of accounts. 
    A) Receiving the user’s main menu input indicating a desire to inquire the amount of his or her balance.
    (this multiple choice question has been scrambled)
  1343. All of the following are true of functions except:  

    A) A function call must specify the name and arguments of the function.  
    B) The implementation of a function is hidden from the caller.
    C) The definition of a function usually is visible to other functions. 
    D) They define specific tasks that can be used at many points in a program. 
    C) The definition of a function usually is visible to other functions.
    (this multiple choice question has been scrambled)
  1344. Functions can:  

    A) Do any of these mentioned. 
    B) Return a result to the caller function.
    C) Be used as building blocks to create new programs. 
    D) Be reused any number of times. 
    A) Do any of these mentioned.
    (this multiple choice question has been scrambled)
  1345. All math library functions:  

    A) Can only be called after creating a math object. 
    B) Must be called by preceding the function name by cmath::. 
    C) Are global functions.
    D) Return data type int. 
    C) Are global functions.
    (this multiple choice question has been scrambled)
  1346. Which of the following expressions returns the trigonometric sine of x?  

    A) sine( x ).
    B) trig_sin( x ). 
    C) sin( x ). 
    D) trig_sine( x ). 
    C) sin( x ).
    (this multiple choice question has been scrambled)
  1347. Which of the following is not included in .math?  

    a) ln. 
    b) pow. 
    c) floor. 
    d) log.
    • d) log.
    • a) ln.
  1348. The function prototype double mySqrt( int x );   

    A) Defines a function called mySqrt which takes an argument of type x and returns a double.
    B) Declares a function called mySqrt which takes a double as an argument and returns an integer. 
    C) Declares a function called mySqrt which takes an integer as an argument and returns a double. 
    D) Defines a function called double which calculates square roots. 
    C) Declares a function called mySqrt which takes an integer as an argument and returns a double.
    (this multiple choice question has been scrambled)
  1349. Using the following function definition, the parameter list is represented by:

     A B ( C )
    {
         D
    }
      
    A) C.
    B) B. 
    C) D. 
    D) A. 
    A) C.
    (this multiple choice question has been scrambled)
  1350. A function prototype does not have to:   

    A) Agree with the function definition.
    B) Include parameter names. 
    C) Terminate with a semicolon. 
    D) Match with all calls to the function. 
    B) Include parameter names.
    (this multiple choice question has been scrambled)
  1351. A function prototype can always be omitted when:  

    A) A function is invoked before it is first defined. 
    B) A function takes no arguments. 
    C) A function is defined before it is first invoked. 
    D) A function does not return a value.
    C) A function is defined before it is first invoked.
    (this multiple choice question has been scrambled)
  1352. Converting from type ________ to type ________ will result in the loss of data.  

    A) int, char. 
    B) float, double. 
    C) bool, char.
    D) short, long. 
    A) int, char.
    (this multiple choice question has been scrambled)
  1353. Each standard library has a corresponding:   

    A) Function. 
    B) Variable type. 
    C) Cd-rom.
    D) Header file. 
    D) Header file.
    (this multiple choice question has been scrambled)
  1354. Which of the following C++ Standard Library header files does not contain a C++ Standard Library container class?  

    A) <string>.  
    B) <list>.
    C) <vector>.  
    D) <stack>.  
    A) <string>.
    (this multiple choice question has been scrambled)
  1355. The rand function generates a data value of the type:  

    A) unsigned int. 
    B) short int.
    C) long int. 
    D) int. 
    A) unsigned int.
    (this multiple choice question has been scrambled)
  1356. A variable that can only have values in the range 0 to 65535 is a:  

    A) Two-byte unsigned int. 
    B) Four-byte int.
    C) Two-byte int. 
    D) Four-byte unsigned int. 
    A) Two-byte unsigned int.
    (this multiple choice question has been scrambled)
  1357. In the expression n = x + rand() % y;  

    A) y is the scaling value. 
    B) y is the shifting value.
    C) x is the scaling value. 
    D) Both (a) and (b). 
    A) y is the scaling value.
    (this multiple choice question has been scrambled)
  1358. srand:  

    A) Is unnecessary in C++. 
    B) Should be used instead of rand to generate truly random numbers. 
    C) Should be called before each call to rand.
    D) Can use the time function’s return value as an optimal seed value. 
    D) Can use the time function’s return value as an optimal seed value.
    (this multiple choice question has been scrambled)
  1359. Enumeration constants: 

    A) Must have unique integer values. 
    B) Must have unique identifiers. 
    C) Can be assigned other values once they have been defined. 
    D) Are declared using the keyword const.
    B) Must have unique identifiers.
    (this multiple choice question has been scrambled)
  1360. An identifier’s storage class:

    A) Determines where the identifier can be referenced in a program. 
    B) Determines the period during which that identifier exists in memory. 
    C) Determines whether an identifier is known only in the current source file or in any source file with proper declarations.
    D) All of these mentioned. 
    B) Determines the period during which that identifier exists in memory.
    (this multiple choice question has been scrambled)
  1361. Depending on the circumstances, the compiler may ignore the storage class specifier:  

    A) static. 
    B) extern. 
    C) auto. 
    D) register.
    D) register.
    (this multiple choice question has been scrambled)
  1362. Which of the following is not true of static local variables?  

    A) They are initialized to zero if not explicitly initialized by the programmer. 
    B) They can be of type int. 
    C) They are accessible outside of the function in which they are defined.
    D) They retain their values when the function in which they are defined terminates.  
    C) They are accessible outside of the function in which they are defined.
    (this multiple choice question has been scrambled)
  1363. Labels are the only identifiers with:  

    A) File scope.
    B) Block scope. 
    C) Function scope. 
    D) Function-prototype scope. 
    C) Function scope.
    (this multiple choice question has been scrambled)
  1364. The only identifiers that can be reused elsewhere in a program without any ambiguity are:  

    A) static local variables. 
    B) Global variables. 
    C) Those in the parameter list of a function definition.
    D) Those in the parameter list of a function prototype. 
    D) Those in the parameter list of a function prototype.
    (this multiple choice question has been scrambled)
  1365. An activation record will be popped off the function call stack whenever:  

    A) A function declares a local variable. 
    B) A function calls another function. 
    C) A function calls itself. 
    D) A function returns control to its caller.
    D) A function returns control to its caller.
    (this multiple choice question has been scrambled)
  1366. Which of the following is not included in a function’s activation record? 

    A) The name of the function.
    B) Parameter values received from its caller.  
    C) The return address of its caller function.  
    D) Local variables it has declared.  
    A) The name of the function.
    (this multiple choice question has been scrambled)
  1367. Which of the following is false about the following function prototype? 

    void functionA( void );  

    A) It does not receive any arguments. 
    B) It could have been written functionA( void );. 
    C) It could have been written void functionA( );. 
    D) It does not return a value.
    B) It could have been written functionA( void );.
    (this multiple choice question has been scrambled)
  1368. The inline keyword:  

    A) Increases function-call overhead. 
    B) Should be used with all frequently used functions. 
    C) Can decrease program size but increase the function’s execution time.
    D) Can reduce a function’s execution time but increase program size. 
    D) Can reduce a function’s execution time but increase program size.
    (this multiple choice question has been scrambled)
  1369. When an argument is passed-by-value, changes in the calling function __________ affect the original variable’s value; when an argument is passed call-by-reference, changes __________ affect the original variable’s value.  

    A) Do not, do not. 
    B) Do not, do. 
    C) Do, do not. 
    D) Do, do.
    B) Do not, do.
    (this multiple choice question has been scrambled)
  1370. A reference parameter:  

    A) Is declared by following the parameter’s type in the function prototype by an ampersand (&).
    B) Both (a) and (b). 
    C) Is an alias for its corresponding argument.  
    D) Cannot be modified.  
    B) Both (a) and (b).
    (this multiple choice question has been scrambled)
  1371. Call-by-reference can achieve the security of call-by-value when:  

    A) The const qualifier is used. 
    B) A pointer to the argument is used.
    C) The value being passed is small. 
    D) A large argument is passed in order to improve performance. 
    A) The const qualifier is used.
    (this multiple choice question has been scrambled)
  1372. In regards to default arguments, which of the following is false?  

    A) They must be the rightmost (trailing) arguments in a function’s parameter list.  
    B) Default values cannot be global variables or function calls. 
    C) Default values can be constants. 
    D) When an argument is omitted in a function call, the default value of that argument is automatically inserted by the compiler and passed in the function call.
    B) Default values cannot be global variables or function calls.
    (this multiple choice question has been scrambled)
  1373. If the function int volume( int x = 1, int y = 1, int z = 1 ); is called by the expression volume( 3 ), how many default arguments are used?   

    A) None. 
    B) One. 
    C) Two.
    D) Three. 
    C) Two.
    (this multiple choice question has been scrambled)
  1374. The unary scope resolution operator is used:   

    A) To access any variable in an outer block when a local variable of the same name is in scope. 
    B) To access a global variable when it is out of scope. 
    C) To access a local variable with the same name as a global variable. 
    D) To access a global variable when a local variable of the same name is in scope.
    D) To access a global variable when a local variable of the same name is in scope.
    (this multiple choice question has been scrambled)
  1375. Which of the following does the C++ compiler not examine in order to select the proper overloaded function to call?  

    A) The return type of the function.  
    B) The number of arguments in the function call.  
    C) Types and order of the arguments in the function call. 
    D) It examines all of these mentioned.
    A) The return type of the function.
    (this multiple choice question has been scrambled)
  1376. If a function’s program logic and operations are identical for each data type it could receive as argument(s) then a __________ should be used.  

    A) Macro. 
    B) Overloaded function. 
    C) Recursive function.
    D) Function template. 
    D) Function template.
    (this multiple choice question has been scrambled)
  1377. A recursive function is a function that:  

    A) Calls itself, directly or indirectly. 
    B) Is inside of another function. 
    C) Takes 3 arguments.
    D) Returns a double. 
    A) Calls itself, directly or indirectly.
    (this multiple choice question has been scrambled)
  1378. Assuming the following pseudocode for the Fibonacci series, what is the value of the 5th Fibonacci number (fibonacci ( 5 ))? 

    fibonacci( 0 ) = 0
    fibonacci( 1 ) = 1
    fibonacci( n ) = fibonacci( n – 1 ) + fibonacci( n – 2 )
       
    A) 1.
    B) 5.  
    C) 7. 
    D) 3. 
    B) 5.
    (this multiple choice question has been scrambled)
  1379. Recursion is to the base case as iteration is to what: 

    A) Failure of the loop continuation test. 
    B) A selection structure. 
    C) The counter.
    D) A repetition structure. 
    A) Failure of the loop continuation test.
    (this multiple choice question has been scrambled)
  1380. An array is not:   

    A) Declared using braces, [].  
    B) A consecutive group of memory locations.  
    C) Subscripted by integers. 
    D) Made up of different data types.
    D) Made up of different data types.
    (this multiple choice question has been scrambled)
  1381. Assuming that int a has a value of 3 and that integer array b has 7 elements, what is the correct way to assign the value of the third element plus 3, to the fifth element of the array:  

    A) b[ a ] + 1 = b[ a + 3];.
    B) b[ a + 1 ] = b[ a ] + 3;. 
    C) b[ a + 1 ] = b[ a - 1 ] + 3;. 
    D) b[ a + 2 ] = b[ a ] + 3;. 
    C) b[ a + 1 ] = b[ a - 1 ] + 3;.
    (this multiple choice question has been scrambled)
  1382. Which of the following is not true?  

    A) A subscript cannot be an expression. 
    B) The first element of an array is the zeroth.
    C) The position number contained within square brackets is called a subscript. 
    D) The last element of an array has position number one less than the array size. 
    A) A subscript cannot be an expression.
    (this multiple choice question has been scrambled)
  1383. Which statement would be used to declare a 10-element integer array c?  

    A) int c[ 10 ];. 
    B) array c = int[ 10 ];.
    C) c = int[ 10 ];. 
    D) int array c[ 10 ];. 
    A) int c[ 10 ];.
    (this multiple choice question has been scrambled)
  1384. Which of the following is not a correct way to initialize an array?  

    A) int n[ 5 ] = { 9, 1, 9 };.
    B) int n[] = { 0, 7, 0, 3, 8, 2 };. 
    C) int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };. 
    D) int n[ 5 ] = { 7 };.  
    C) int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };.
    (this multiple choice question has been scrambled)
  1385. Constant variables:  

    A) Do not have to be initialized when they are declared. 
    B) Can be used to specify array sizes, thereby making programs more scalable. 
    C) Can be assigned values in executable statements.
    D) Can be used to specify array sizes, but this makes programs harder to understand. 
    B) Can be used to specify array sizes, thereby making programs more scalable.
    (this multiple choice question has been scrambled)
  1386. Referencing elements outside the array bounds:    

    A) Is a syntax error. 
    B) Can result in changes to the value of an unrelated variable.  
    C) Is impossible because C++ checks to make sure it does not happen.
    D) Enlarges the size of the array. 
    B) Can result in changes to the value of an unrelated variable.
    (this multiple choice question has been scrambled)
  1387. Strings represented as character arrays cannot:   

    A) Be initialized with initializer lists. 
    B) Be used with cout and cin.
    C) Be initialized using string literals. 
    D) Grow or shrink dynamically.  
    D) Grow or shrink dynamically.
    (this multiple choice question has been scrambled)
  1388. Exception __________________ occurs when an input/output error occurs when closing a socket.
    IOException
  1389. Exception __________________ occurs when a hostname indicated by a client cannot be resolved.
    UnknownHostException
  1390. If a DatagramSocket constructor fails to set up a DatagramSocket properly, an exception of type ________________________ occurs.
    SocketException
  1391. ___________ sockets and the _____________ protocol are more desirable for the vast majority of Java programmers.

    A) Stream, UDP
    B) Datagram, UDP
    C) Datagram,TCP
    D) Stream, TCP
    D) Stream, TCP
    (this multiple choice question has been scrambled)
  1392. (Textbook Page 1119-1120)
  1393. Many of Java’s networking classes are contained in package ____________________.
    java.net
  1394. Class _____________ binds the application to a port for Datagram transmission.
    DatagramSocket
  1395. To be able to send and receive messages in parallel over a network connection, a program must use _____________________ of execution.

    A) two threads
    B) one thread
    C) three threads
    D) four threads
    A) two threads
    (this multiple choice question has been scrambled)
  1396. The two types of sockets discussed in chapter 27 are ___________ and ______________.
    stream sockets, datagram sockets
  1397. An object of class __________________ contains an IP address.
    InetAddress
  1398. The acronym URL stands for ____________________________.
    Uniform Resource Locator
  1399. Which statement is false?

    A) Connection-oriented transmission is like the telephone system
    B) Data-gram based transmission is connection oriented.
    C) Streams-based transmission is connection-oriented.
    D) Connectionless transmission is like the way the mail is carried by the postal service.
    B) Data-gram based transmission is connection oriented.
    (this multiple choice question has been scrambled)
  1400. The acronym URI stands for _________________________.
    Uniform Resource Identifier
  1401. Specifying a port that is already in use or specifying an invalid port number when creating a DatagramSocket results in _____________________________.

    A) SocketException
    B) PortInUseException
    C) ConnectException
    D) PortException
    A) SocketException
    (this multiple choice question has been scrambled)
  1402. (Textbook Page 1143)
  1403. The key protocol that forms the basis of the World Wide Web is _____________________.
    HTTP
  1404. AppletContext method _______________ receives a URL object as an argument and displays in a browser the World Wide Web resources associated with that URL.
    ShowDocument
  1405. Method getLocalHost returns a(n)________________ object containing the local IP address of the computer on which the program is executing.
    InetAddress
  1406. The URL constructor determines whether its String argument is a valid URL. If so, the URL object is initialized with that location. If not, a(n) _________________ exception occurs.
    MalformedURLException
  1407. A(n) ____________________ is thrown when a server address indicated by a client cannot be resolved.

    A) ServerException
    B) ConnectionException
    C) MalformedURLException
    D) UnknownHostException
    D) UnknownHostException
    (this multiple choice question has been scrambled)

What would you like to do?

Home > Flashcards > Print Preview