6. System, String, StringBuffer, Math, and Wrapper Classes Most of the Date class methods have been deprecated. Which of the following methods is one of those that have been deprecated? 不推荐 *B. getDate() Which line of code will create a new string in the string pool that can be referenced by the identifier myGame? *A. String myGame = "basketball"; Which lines of code produce the following output? Hello How are you? *D. System.out.println("Hello"); System.out.println("How are you?"); Which package(s) are usually imported when using dates in a program? *D. java.util.* and java.text.* the screen. Which type of data does the System.in.read() method read? *C. It reads in a byte at a time and returns an integer in the range of 0 to 255. What must be imported to use System.out.println()? *D. nothing What is printed out to the screen when the code in the listing provided is executed? *B. The answer is 2.345 What happens if you try to use the following code? Double num1 = new Double(1.23); double num2 = num1.doubleValue(); *D. It will compile and num2 will have the value of 1.23. Which would be the best StringBuffer method to use to change the StringBuffer object containing "bob saw mom" to a StringBuffer object containing "mom was bob"? *D. reverse() What must you do when using a primitive data method? *C. Primitive data does not have methods. What is the value of s2 after this code executes? String s1 = "Happy day"; String s2 = s1.substring(1,5); *C. "appy" If you are writing a piece of code that needs to determine whether the user entered 'q' to quit, not knowing if they would use upper or lowercase, which method(s) would you use? The user's response is held in the char variable choice . *D. Character.toUpperCase(), and the comparison operator, == What happens if you use the compareTo() method and send an object that is not a String as a parameter? *B. The compareTo() method will throw an exception. Which of the following is true about the Console class used in this and subsequent chapters? *B. It is a class written for us to use in this course to simplify input and output operations. Which of the following is a true statement about the toString() method of the StringBuffer class? *B. It converts the data in the StringBuffer to a String and returns that new String. Which method can you call to obtain the integer version of a String? *A. Integer.parseInt() Where can you find the documentation for the java.math package? *A. Sun Java documentation 7. Arrays What is the index of the last element in an array? *D. The size of the array minus one. What happens when an array of objects is created? *A. The array contains locations for references to objects of the specified type. What is the proper syntax for accessing the fifth element of an array? *D. theArray [4] What is contained in each element of the array when the following statements are executed? int numbers []; numbers = new numbers [2]; *B. 0 How many elements are in dblArray? *B. 7 What is the output of the displayed code? *D. 4.0, 8.0, 12.0, 16.0, 20.0, 24.0, Which class actually contains the line that prints the artist to the screen? *C. The artist is printed from the Song class. Which string is listed on the screen first? *B. The song on track What is the order of the array in the graphic after it has been sorted in ascending order? *A. 1, 2, 3, 6 What is the output of the program in the graphic? *E. 20 Which of the following statements correctly defines the term "array?" *A. A variable reference to a java object that can access a sequence of contiguous storage locations storing the same type of data. What is the correct syntax for declaring an array? *B. int[] quantity; Which of the following lines of code displays the correct syntax for initializing an array with default values? *A. int[ ] quantity = {4, 5, 6, 78,100}; If a code references an element of an array for which there is no index, what type of exception is generated? *D. IndexOutOfBoundsException What is the most efficient way to store and randomly access a sequence of objects that Java provides? *D. Array Where is the array and the objects that each element references stored? *C. Heap What does the following line of code do? quantity = new int[3]; *B. Creates storage for three int. What is combined with the name of the array variable to provide a reference to a single element of the array? *C. Index value Which term is used for storing values in an array? *D. Populating When programmers need to initialize a large number of variables with a calculated value, what should they create? *B. StudentsInTheClass[1]=new student (456778998, "Peter Lei") When primitive data is stored on the heap, it is initialized with what value? *C. Default value of the data-type In order for a static method to access any non-static methods of a class, what must it contain? *B. Object instance When the values of each element in one array correspond to the meaning of the values in a second array, what are the arrays known as? *A. Parallel arrays What is a requirement for the creation and initialization of multidimensional arrays? *D. Each dimension must be created before it can initialize values for the next dimension. What is the output of the Java code? *B. The element at 1 is 4. The element at 2 is 2. The element at 3 is 5. The element at 4 is 3. 8. Classes and Inheritance The phrase "a method that converts a reference value of an object to a string" correctly defines which of the following methods? *C. toString() Which of the following can be used as an abstract representation of behaviors? *B. super class The phrase "The super class for all classes" refers to which class? *B. Object Which keyword is used to make a class definition include the non-private attributes and behaviors of a parent class, as well as additional attributes and behaviors that are specific to the class being defined? *A. extends Which term refers to the process of redefining or customizing the definition of a parent class method? *B. overriding Which of the following statements is incorrect? *C. Class fourWDTruck inherits from class Truck so Truck 'is a' fourWDTruck Which method is called by the garbage collector before an object is destroyed? *D. finalize() Inheritance defines which type of relationships among classes and objects? *A. is-a What can be used as an abstract representation of common behaviors and data among objects? *C. data member In Java, a class can inherit from how many other classes? *A. one What would be the best parent class for these items: apple, orange, tomato, and kiwi? *C. Fruit What is the purpose of Dynamic Binding? *B. It resolves what method to call when a method is implemented by more than one class in the inheritance hierarchy. Which term refers to the path from a specific class to its ancestors? *B. inheritance hierarchy Which of the following is incorrect? *D. A class automatically extends class Object and can extend any number of other classes. Which term refers to the mechanism in the Java language that adds enormous flexibility to your programs? *A. polymorphism What is it called when methods have the same name and can perform different tasks depending on the subclass that calls the method? *B. polymorphism Which of the following statements is incorrect? *B. The keyword 'super' functions the same as 'me.' Which statement is correct? *C. When a super class is an abstract representation, the super class cannot be used as an object. In general, your class design should include overridden methods for which of the following? *A. equals(), hashcode(), toString() The phrase "a class from which no objects are expected to be created" refers to which of the following terms? *A. abstract class Which class would Person be considered, if employee and Customer both inherit common behaviors from the Person class? *C. parent Which of the following is incorrect? *D. An abstract class generally provides all the functionality needed for any class that inherits from it. Which keyword is used to prevent a class from being extended? *D. final Which access modifier must be applied to a method when creating an interface? *A. public Which of the following statements is incorrect? *D. An extended class definition includes all private attributes and behaviors of the parent. 9. Understanding Packages Which one of the AWT class categories can be used to hold other components? *B. Applet Which of the following AWT classes is used to position components in a container? *A. FlowLayout Which of the following utilities can be used to combine all the files in a package into a single compressed file? *D. jar What information does the PATH variable of an Operating System contain? *B. Program executable directories GUI programs fall into which of the following programming paradigms? *C. event driven Which of the following allows the management of classes that are part of a collection? *C. Packaging Which of the following AWT classes can draw graphics or manipulate images? *B. Graphics Which file extension will end a source code file or compilation unit? *C. .java Which component can house other components? *A. containers Which of the following statements is used to locate classes that are part of a package? *D. import statement Suppose you are an entry-level programmer starting to layout a new application. Your supervisor tells you to make sure you create your java application using packages because packages are easier to manage. Why would packages be easier to manage? *B. Because the program will be created as a collection of classes. Which of the following statements is true concerning the use of packages? *C. Minimizes name collision Which of the following are identifiers of a class and it's methods? *B. Namespaces Which of the following is the term used to identify the hierachy of directories where a file is located? *D. Path What are the two variables that affect class files and JDK programs? *A. Path and Classpath Packages are used to control the naming of classes. For example, standard library math functions are in the Math class, which is in the java.lang package. Based on the information given, what is the complete name of this class? *C. java.lang.Math Which utility is used to improve management and delivery of classes? *B. jar 10. Creating GUIs Using AWT ContainerListener is an interface name for the container category. This particular interface name has methods associated with it. Which of the following is a valid method associated with the container category? *D. componentAdded What is true about the BorderLayout class? *B. It divides the Container that uses it into five sections. Which is a difference between the FlowLayout and the BorderLayout? *A. In FlowLayout the components may move from one row to another when the panel is resized, but with a BorderLayout the components stay within their region. Which of the following lines of code would create a Button object that has the label "Exit"? *C. Button bt = new Button("Exit"); Which of the following lines of code will set the layout of a Frame named fr to BorderLayout? *C. fr.setLayout(new BorderLayout()); Which of the following is a region for a BorderLayout? *A. Center What is one difference between a Window object and a Panel object? *A. A Window object does not need to be in another Container, while a Panel object must. What is the AWT? *A. Abstract Windowing Toolkit Which of the following is true about the Panel class? *B. Panel objects must be contained in another Container object. Creating a GUI involves many steps that have to be considered with equal importance. According to the chapter readings, how many steps are there in the process? *D. 8 The BorderLayout is the default layout for which class of Components? *C. Frame Which of the following is true about layout managers? *B. Every container has a default layout manager. In Java's event delegation model, which section refers to the event object that encapsulates information about the event? *B. The event What is the best way to handle the sizing of the Components in a Container? *B. Let the layout manager handle the sizing. In Java's event delegation model, which section refers to the object that can generate an event object? *C. the source of an event What is the class that is used to set some properties of components and graphics? *A. FontMetrics What are the maximum number of Components you can place in a Container that uses the BorderLayout? *D. 5 What method of the Container class is used to put Components in either a Window or a Panel object? *C. add() Which of the following is a true statement? *D. The TextArea class and the TextField class are both subclasses of the TextComponent class. Which layout allows you to arrange Components that are stacked on top of each other like a deck of cards? *A. CardLayout John Smith has been hired to build a fully functional java application with a GUI interface. Which of the following components would likely require the most code? *A. Graphical User Interface (GUI) Which lines of code would add a button to the top region of an Applet using a BorderLayout? private Button bt = new Button("At the top"); setLayout(new BorderLayout()); *C. add(bt, "North"); In Java's event delegation model, which section refers to the object that can handle the event, the event that is performing some task? *A. The handler What is the name of the abstract class that is an ancestor class for all the objects that you see in a GUI? *D. Component Which Component would you use to allow the user to select one or more options? *C. List