Chapter 8 Classes and Objects: A Deeper Look, Java Chapter 8 quiz, JAVA CH8, Chapter 9 Java 401, Ch. 10, Java Quizzes 10-end, Chapter 9 Inheritance

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following statements is false? A TextField (package javafx.scene.control) can accept text input or display text. Each component in a GridPane can span multiple columns or rows. Each cell in a GridPane can be empty or can hold one or more JavaFX components, including layout containers that arrange other controls. A Slider (package javafx.scene.control) represents a value in the range 0.0- 1.0 by default and allows the user to select a number in that range by moving the Slider's thumb.

A Slider (package javafx.scene.control) represents a value in the range 0.0- 1.0 by default and allows the user to select a number in that range by moving the Slider's thumb.

Which of the following statements is false? Each component in a GridPane can span multiple columns or rows. A Slider (package javafx.scene.control) represents a value in the range 0.0- 1.0 by default and allows the user to select a number in that range by moving the Slider's thumb. Each cell in a GridPane can be empty or can hold one or more JavaFX components, including layout containers that arrange other controls. A TextField (package javafx.scene.control) can accept text input or display text.

A Slider (package javafx.scene.control) represents a value in the range 0.0- 1.0 by default and allows the user to select a number in that range by moving the Slider's thumb.

What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor?

A compilation error occurs.

Which of the following is false?

A static method can call instance methods directly.

8.5 Q4: What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor? a. a. A compilation error occurs. b. b. A runtime error occurs. c. c. A logic error occurs. d. d. Nothing happens. The program compiles and runs.

ANS: a. A compilation error occurs.

8.3 Q2: Which of the following statements is true? a. a. Methods and instance variables can both be either public or private. b. b. Information hiding is achieved by restricting access to class members via keyword public. c. c. The private members of a class are directly accessible to the client of a class. d. d. None of the above is true.

ANS: a. Methods and instance variables can both be either public or private.

8.6 Q1: Which statement is false? a. a. The compiler always creates a default constructor for a class. b. b. If a class's constructors all require arguments and a program attempts to call a no-argument constructor to initialize an object of the class, a compilation error occurs. c. c. 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. d. d. None of the above.

ANS: a. The compiler always creates a default constructor for a class.

8.16 Q6: The import declaration import *; ________. a. a. causes a compilation error. b. b. imports all classes in the library. c. c. imports the default classes in the library. d. d. imports the classes in package java.lang.

ANS: a. causes a compilation error.

8.9 Q1: enum types are implicitly ________ and enum constants are implicitly ________. a. a. final, static. b. b. static, static. c. c. static, final. d. d. final, final. .

ANS: a. final, static

8.9 Q3: Which method returns an array of the enum's constants? a. a. values. b. b. getValues. c. c. constants. d. d. getConstants.

ANS: a. values.

8.16 Q2: A class within a package must be declared public if a. a. It will be used only by other classes in the same package. b. b. It will be used by classes that are not in the same package. c. c. It is in the same directory as the other classes in the package. d. d. It has a unique name.

ANS: b. 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.

8.2 Q2: The static method ________ of class String returns a formatted String. a. a. printf. b. b. format. c. c. formatString. d. d. toFormatString.

ANS: b. format.

8.8 Q1: Composition is sometimes referred to as a(n) ________. a. a. is-a relationship. b. b. has-a relationship. c. c. many-in-one relationship. d. d. one-to-many relationship.

ANS: b. has-a relationship.

8.12 Q1: Which syntax imports all static members of class Math? a. a. static import java.lang.Math.*. b. b. import static java.lang.Math.*. c. c. static import java.lang.Math. d. d. import static java.lang.Math.

ANS: b. import static java.lang.Math.*.

8.5 Q3: A programmer-defined constructor that has no arguments is called a(n) ________. a. a. empty constructor. b. b. no-argument constructor. c. c. default constructor. d. d. null constructor.

ANS: b. no-argument constructor.

8.5 Q5: When implementing a method, use the class's set and get methods to access the class's ________ data. a. a. public. b. b. private. c. c. protected. d. d. All of the above.

ANS: b. private.

8.16 Q7: The classpath consists of a list of directories or archive files, each separated by a ________ on Windows or a ________ on UNIX/Linux/Max OS X. a. a. colon (:), semicolon (;). b. b. semicolon (;), colon (:). c. c. comma (,), semicolon (;). d. d. semicolon (;), comma (,).

ANS: b. semicolon (;), colon (:).

8.16 Q4: When compiling a class in a package, the javac command-line option ________ causes the javac compiler to create appropriate directories based on the class's package declaration. a. a. -p. b. b. -a. c. c. -d. d. d. -dir.

ANS: c. -d.

8.4 Q1: When should a program explicitly use the this reference? a. a. Accessing a private variable. b. b. Accessing a public variable. c. c. Accessing a local variable. d. d. Accessing a field that is shadowed by a local variable.

ANS: c. Accessing a field that is shadowed by a local variable.

8.9 Q2: Which statement is false? a. 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. b. Any attempt to create an object of an enum type with operator new results in a compilation error. c. c. An enum constructor cannot be overloaded. d. d. An enum constructor can specify any number of parameters.

ANS: c. An enum constructor cannot be overloaded.

8.13 Q1: Instance variables declared final do not or cannot: a. a. Cause syntax errors if used as a left-hand value. b. b. Be initialized. c. c. Be modified. d. d. None of the above.

ANS: c. Be modified.

8.17 Q1: When no access modifier is specified for a method or variable, the method or variable: a. a. Is public. b. b. Is private. c. c. Has package access. d. d. Is static.

ANS: c. Has package access.

8.10 Q1: Which of the following is false? a. a. Method finalize does not take parameters and has return type void. b. b. Memory leaks using Java are rare because of automatic garbage collection. c. c. Objects are marked for garbage collection by method finalize. d. d. The garbage collector reclaims unused memory.

ANS: c. Objects are marked for garbage collection by method finalize. (Objects are marked for garbage collection when there are no more references to the object).

Q1: Which of the following should usually be private? a. a. Methods. b. b. Constructors. c. c. Variables (or fields). d. d. All of the above. ANS: c. Variables (or fields).

ANS: c. Variables (or fields).

8.7 Q1: Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods. a. a. query, mutator. b. b. accessor, mutator. c. c. mutator, accessor. d. d. query, accessor.

ANS: c. mutator, accessor.

8.2 Q1: The _________ of a class are also called the public services or the public interface that the class provides to its clients. a. a. public constructors. b. b. public instance variables. c. c. public methods. d. d. All of the above.

ANS: c. public methods.

8.5 Q1: A constructor cannot: a. a. be overloaded. b. b. initialize variables to their defaults. c. c. specify return types or return values. d. d. have the same name as the class.

ANS: c. specify return types or return values.

8.2 Q3: Which statement is false? a. a. The actual data representation used within the class is of no concern to the class's clients. b. b. Clients generally care about what the class does but not how the class does it. c. c. Clients are usually involved in a class's implementation. d. d. Hiding the implementation reduces the possibility that clients will become dependent on class-implementation details.

ANS: c: Clients are usually involved in a class's implementation

8.16 Q1: A package is: a. a. A directory structure used to organize classes and interfaces. b. b. A mechanism for software reuse. c. c. A group of related classes and interfaces. d. d. All of the above.

ANS: d. All of the above.

8.4 Q2: Having a this reference allows: a. a. a method to refer explicitly to the instance variables and other methods of the object on which the method was called. b. b. a method to refer implicitly to the instance variables and other methods of the object on which the method was called. c. c. an object to reference itself. d. d. All of the above.

ANS: d. All of the above.

8.7 Q3: Using public set methods provides data integrity if: a. a. The instance variables are public. b. b. The instance variables are private. c. c. The methods perform validity checking. d. d. Both b and c.

ANS: d. Both b and c.

8.5 Q2: Constructors: a. a. Initialize instance variables. b. b. When overloaded, can have identical argument lists. c. c. When overloaded, are selected by number, types and order of types of parameters. d. d. a and c.

ANS: d. a and c.

8.11 Q1: Static class variables: a. a. are final. b. b. are public. c. c. are private. d. d. are shared by all objects of a class.

ANS: d. are shared by all objects of a class.

8.16 Q8: By default, the classpath consists only of the ________. However, the classpath can be modified by providing the ________ option to the javac compiler. a. a. root directory of the package, -d. b. b. current directory, -d. c. c. root directory of the package, -classpath. d. d. current directory, -classpath.

ANS: d. current directory, -classpath.

8.13 Q2: A final field should also be declared ________ if it is initialized in its declaration. a. a. private. b. b. public. c. c. protected. d. d. static.

ANS: d. static.

8.16 Q5: The import declaration import java.util.*; is known as a ________. a. a. single-type-import declaration. b. b. all-type-import declaration. c. c. multiple-import declaration. d. d. type-import-on-demand declaration.

ANS: d. type-import-on-demand declaration.

Which of the following statements is false? An event handler is a method that responds to a user interaction. An FXML GUI's event handlers are defined in a controller class. The nodes arranged in a layout container are a combination of controls and possibly other layout containers. All of the choice statements are true. When the user interacts with a control, it generates an event. Programs can use event handling to specify what should happen when each user interaction occurs.

All of the choice statements are true.

Which of the following statements is false? All of the choices are true. You can set a Button's text by double clicking it, or by selecting the Button, then setting its Text property in the Inspector window's Properties section. Setting a node's Pref Width property of a GridPane column to USE_COMPUTED_SIZE indicates that the width should be based on the widest child. A GridPane column's contents are left-aligned by default.

All of the choices are true.

Which of the following statements is false? Providing different apps with consistent, intuitive user-interface components gives users a sense of familiarity with a new app, so that they can learn it more quickly and use it more productively. A graphical user interface (GUI) presents a user-friendly mechanism for interacting with an app. A GUI (pronounced "GOO-ee") gives an app a distinctive "look-and-feel." All of the choices are true. GUIs are built from GUI components—sometimes called controls or widgets.

All of the choices are true.

Which statement is false?

An enum constructor cannot be overloaded.

A JavaFX app's main class directly inherits from ________. Application Main Object App

Application

Which of the following statements is false? As of Java SE 8, an anonymous inner class can access its top-level class's instance variables, static variables and methods, but has limited access to the local variables of the method in which it's declared—it can access only the final local variables declared in the enclosing method's body. Since an anonymous inner class has no name, one object of the class must be created at the point where the class is declared. An anonymous inner class is a class that's declared without a name and typically appears inside a method declaration. The @FXML annotation preceding an instance variable indicates that the variable's name can be used in the FXML file that describes the app's GUI.

As of Java SE 8, an anonymous inner class can access its top-level class's instance variables, static variables and methods, but has limited access to the local variables of the method in which it's declared—it can access only the final local variables declared in the enclosing method's body.

Instance variables declared final do not or cannot

Be modified after they are initialized.

Which statement is false?

Clients are usually involved in a class's implementation.

Which of the following statements is false? The code that performs a task in response to an event is called an event handler. For certain events you can link a control to its event-handling method by using the Code section of Scene Builder's Inspector window. In this case, the event- listener interface is implemented for you to call the method that you specify. When the user interacts with a GUI component, the interaction—known as an event—drives the program to perform a task. For events that occur when the value of a control's property changes, you must create the event handler entirely using only drag and drop in Scene Builder.

For events that occur when the value of a control's property changes, you must create the event handler entirely using only drag and drop in Scene Builder.

When no access modifier is specified for a method or variable, the method or variable:

Has package access.

Having a this reference allows

Having a this reference permits all of these.

Which of the following statements is true?

Methods and instance variables can both be either public or private.

Stage method show displays the ________. scene graph Stage window root node title bar

Stage window

Which of the following statements is false?

The BigDecimal method format receives a double argument and returns a BigDecimal object that represents the exact value specied.

Which of the following statements is false? JavaFX Scene Builder enables you to create GUIs by dragging and dropping GUI components from Scene Builder's library onto a design area, then modifying and styling the GUI—all without writing any code. JavaFX Scene Builder is a standalone JavaFX GUI visual layout tool that can also be used with various IDEs. The FXML code is integrated with the program logic that's defined in Java source code—this integration of the interface (the GUI) with the implementation (the Java code) makes it easier to debug, modify and maintain JavaFX GUI apps. JavaFX Scene Builder generates FXML (FX Markup Language)—an XML vocabulary for defining and arranging JavaFX GUI controls without writing any Java code

The FXML code is integrated with the program logic that's defined in Java source code—this integration of the interface (the GUI) with the implementation (the Java code) makes it easier to debug, modify and maintain JavaFX GUI apps.

Which statement is false?

The compiler always creates a default constructor for a class.

Using public set methods helps provide data integrity if:

The instance variables are private AND the methods perform validity checking.

Which of the following class members should usually be private?

Variables (or fields).

Which of the following statements is false? When adding controls to a VBox, each new control is placed adjacent to the preceding ones by default. To specify an ImageView's size, set its Fit Width and Fit Height properties in the Inspector's Layout section. To set the image to display, select the ImageView then set its Image property in the Inspector's Properties section. You can set a Label's text either by double clicking it and typing the text, or by selecting the Label and setting its Text property in the Inspector's Properties section.

When adding controls to a VBox, each new control is placed adjacent to the preceding ones by default.

Which of the following statements is false? You can specify the default amount of space between a GridPane's columns and rows with its Hgap (horizontal gap) and Vgap (vertical gap) properties, respectively. When you click an interactive control, it prompts for input. When you press the Tab key, the focus transfers from the current focusable control to the next one—this occurs in the order the controls were added to the GUI. You can type in a TextField only if it's "in focus"—that is, it's the control that the user is interacting with.

When you click an interactive control, it prompts for input.

Which of the following statements is false? All of the choice statements are true. You also can copy and paste a VBox from the Containers section in the Library onto Scene Builder's content panel. To add a VBox to Scene Builder's content panel, double-click VBox in the Library window's Containers section. You also can drag-and-drop a VBox from the Containers section in the Library onto Scene Builder's content panel.

You also can drag-and-drop a VBox from the Containers section in the Library onto Scene Builder's content panel.

Stage method setScene places ________. the root node text in the Stage window's title bar the gradient on the Stage a Scene onto a Stage

a Scene onto a Stage

What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor? a. A compilation error occurs. b. A runtime error occurs. c. A logic error occurs. d. Nothing happens. The program compiles and runs.

a. A compilation error occurs

Which statement is false? a. The compiler always creates a default constructor for a class. b. If a class's constructors all require arguments and a program attempts to call a no-argument constructor to initialize an object of the class, a compilation error occurs. c. 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. d. None of the above.

a. The compiler always creates a default constructor for the class.

Which of the following statements is true? a. Methods and instance variables can both be either public or private. b. Information hiding is achieved by restricting access to class members via keyword public. c. The private members of a class are directly accessible to the clients of a class. d. None of the above is true.

a. methods and instance variables can both be either public or private.

Which method returns an array of the enum's constants? a. values. b. getValues. c. constants. d. getConstants.

a. values

BigDecimal gives you control over how values are rounded. By default:

all calculations are exact and no rounding occurs.

A programmer-defined constructor that has no arguments is called a(n) ________. a. empty constructor. b. no-argument constructor. c. default constructor. d. null constructor.

b. a no-argument constructor

The static method ________ of class String returns a formatted String. a. printf. b. format. c. formatString. d. toFormatedString.

b. format

Composition is sometimes referred to as a(n) ________. a. is-a relationship b. has-a relationship c. many-to-one relationship d. one-to-many relationship

b. has-a relationship

Which syntax imports all static members of class Math? a. import java.lang.Math.*. b. import static java.lang.Math.*. c. import static java.lang.Math. d. None of the above.

b. import static java.lang.Math.*

When implementing a method, use the class's set and get methods to access the class's ________ data. a. public. b. private. c. protected. d. All of the above.

b. private

BigDecimal gives you control over how values are rounded. By default: a. all calculations are approximate and no rounding occurs. b. all calculations are approximate and rounding occurs. c. all calculations are exact and no rounding occurs. d. all calculations are exact and rounding occurs.

c. All calculations are exact and no rounding occurs.

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 after they are initialized. d. None of the above.

c. Be modified after they are initialized.

When no access modifier is specified for a method or variable, the method or variable: a. Is public. b. Is private. c. Has package access. d. Is static.

c. Has package access.

Which of the following is false? a. Method finalize does not take parameters and has return type void. b. Memory leaks using Java are rare because of automatic garbage collection. c. Objects are marked for garbage collection by method finalize. d. The garbage collector reclaims unused memory.

c. Objects are marked for garbage collection by method finalize.

The _________ of a class are also called the public services or the public interface that the class provides to its clients. a. public constructors. b. public instance variables. c. public methods. d. All of the above.

c. Public methods

A constructor cannot: a. be overloaded. b. initialize variables to their defaults. c. specify return types or return values. d. have the same name as the class.

c. Specify return types or return values.

Which of the following class members should usually be private? a. Methods. b. Constructors. c. Variables (or fields). d. All of the above.

c. Variables (or fields)

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 new results in a compilation error. c. An enum constructor cannot be overloaded. d. enum constants are implicitly final and static.

c. an enum constructor cannot be overloaded.

Which statement is false? a. The actual data representation used within the class is of no concern to the class's clients. b. Clients generally care about what the class does but not how the class does it. c. Clients are usually involved in a class's implementation. d. Hiding the implementation reduces the possibility that clients will become dependent on class-implementation details.

c. client's are usually involved in a class' implementation.

Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods. a. query, mutator. b. accessor, mutator. c. mutator, accessor. d. query, accessor.

c. mutator, accessor

In a JavaFX FXML app, you define the app's event handlers in a________ class, which defines instance variables for interacting with controls programmatically, as well as event-handling methods. view model data controller

controller

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 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

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

Constructors: a. Initialize instance variables. b. When overloaded, can have identical argument lists. c. When overloaded, are selected by number, types and order of types of parameters. d. Both (a) and (c).

d. Both a and c

Static class variables: a. are final. b. are public. c. are private. d. are shared by all objects of a class.

d. Shared by all objects of a class.

Which of the following statements is false? a. An application that requires precise floating-point calculations such as those in financial applications should use class BigDecimal from package java.math. b. We use class NumberFormat for formatting numeric values as locale-specific strings. c. In the U.S, locale, the value 15467.82 would be formatted as "15,467.82", whereas in many European locales it would be formatted as "15.467,56". d. The BigDecimal method format receives a double argument and returns a BigDecimal object that represents the exact value specied.

d. The BigDecimal method format receives a double argument and returns a BigDecimal object that represents the exact value specified.

Which of the following statements is false? a. If a program uses multiple classes from the same package, these classes can access each other's package access members directly through references to objects of the appropriate classes, or in the case of static members, through the class name. b. Package access is rarely used. c. Classes in the same source file are part of the same package. d. Use the access modifier package to give a method or variable package access.

d. Use the access modifier package to give a method or variable package access

When must a program explicitly use the this reference? a. Accessing a private variable. b. Accessing a public variable. c. Accessing a local variable. d. Accessing an instance variable that is shadowed by a local variable

d. accessing an instance variable that is shadowed by a local variable.

Using public set methods helps provide data integrity if: a. The instance variables are public. b. The instance variables are private. c. The methods perform validity checking. d. Both b and c.

d. both b and c

8.11 Q2: Which of the following is false? a. a. A static method must be used to access private static instance variables. b. b. A static method has no this reference. c. c. A static method can be accessed even when no objects of its class have been instantiated. d. d. A static method can call instance methods directly.

d. d. A static method can call instance methods directly.

A final field should also be declared ________ if it is initialized in its declaration. a. private. b. public. c. protected. d. static.

d. static

Composition is sometimes referred to as a(n) ________.

has-a relationship

Which syntax imports all static members of class Math?

import static java.lang.Math.*.

Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods.

mutator;accessor

A programmer-defined constructor that has no arguments is called a(n) ________.

no-argument constructor.

Class NumberFormat of package java.text provides numeric formatting capabilities, such as ________. neither percentage formats nor locale-specific currency formats locale-specific currency formats percentage formats percentage formats and locale-specific currency formats

percentage formats and locale-specific currency formats

The _________ of a class are also called the public services or the public interface that the class provides to its clients.

public methods.

A constructor cannot:

specify return types or return values.

The window in which a JavaFX app's GUI is displayed is known as the________. rostrum podium main window stage

stage

Which method returns an array of the enum constants?

values.

Layout containers help you arrange GUI components. A VBox arranges its nodes________. None of the choices. vertically from top to bottom by best fit left to right

vertically from top to bottom

Layout containers help you arrange GUI components. A VBox arranges its nodes________. vertically from top to bottom left to right by best fit None of the choices.

vertically from top to bottom


Ensembles d'études connexes

Week 1: Chapter 3 (Older adult) / Chapter8 (Rehab)/ ATI Books

View Set

Hinkle Chapter 53: Assessment of Kidney and Urinary Function

View Set

ECON 200 LS Measuring Output & Income

View Set