Java: Chapter 10, Java Chapter 15, Java Chapters 14 and 15, Java Chapter 14, Java Chapter 16, Java final (ch. 11)

Ace your homework & exams now with Quizwiz!

In the hierarchy of Exception classes, the NumberFormatException class is a subclass of the ____ class.

IllegalArgumentException

Which exception class should you use from the standard library if you want to thrown an exception when there are insufficient funds in a bank account to cover a withdrawal?

IllegalArgumentException

what is the purpose of the throw statement?

it is used to pass control to an error handler when an error situation is detected

You can use the properties _________ in a MediaView. A. x B. y C. mediaPlayer D. fitWidth E. fitHeight

A. x B. y C. mediaPlayer D. fitWidth E. fitHeight

To place a node in the left of a BorderPane p, use ___________. A. p.setEast(node); B. p.placeLeft(node); C. p.setLeft(node); D. p.left(node);

C. p.setLeft(node);

To add a circle object into a pane, use _________. A. pane.add(circle); B. pane.addAll(circle); C. pane.getChildren().add(circle); D. pane.getChildren().addAll(circle);

C. pane.getChildren().add(circle); D. pane.getChildren().addAll(circle);

Which of the following is an example of a lambda expression? A) All of these B) IntCalculator = new divider(x, 2); C) int x = x * factor; D) IntCalculator multiplier = x and x * factor;

D) IntCalculator multiplier = x and x * factor;

15.30 Which of the following methods is not defined in the Animation class? A. pause() B. play() C. stop() D. resume()

D. resume()

Look at the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB() {} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC() {} Line 14 public void method1() {} Line 15 } Which method1 will be executed when the following statements are executed? ClassA item1 = new ClassB(); item1.method1(); A) Line 9 B) Line 14 C) Line 4 D) This is an error and will cause the program to crash.

A) Line 9

When declaring class data members, it is best to declare them as: A) private members B) restricted members C) protected members D) public members

A) private members

When an interface variable references an object, you can use the interface variable to call any and all of the methods in the class implementing the interface. True/False

False

Assuming that the string input contains the digits of an integer, without any additional characters, which expression obtains the corresponding numeric value?

Integer.parseInt(input)

An example of a fatal error that rarely occurs and is beyond your control is the ____.

OutOfMemoryError

Your program wishes to open a file named C:\java\myProg\input.txt on a Windows system. Which of the following is the correct code to do this?

inputFile = new File("c:\\java\\myProg\\input.txt");

Assume inputFile is a Scanner object used to read data from a text file that contains a number of lines. Each line contains an arbitrary number of words, with at least one word per line. Select an expression to complete the following code segment, which prints the last word in each line. while (inputFile.hasNextLine()) { String word = ""; String line = inputFile.nextLine(); Scanner words = new Scanner(line); while (_________________) { word = words.next(); } System.out.println(word); }

words.hasNext()

which of the following statements about reading and writing text files is correct?

you use the Scanner class to read text files and the PrintWriter class to write text files.

Consider the following code snippet: File inputFile = new File(filename); try (Scanner in = new Scanner(inputFile)) { . . . } catch (Exception e) { } Which of the following statements about this code is correct?

This code will catch exceptions that occur in the try block but will do nothing about the exceptions.

Consider the following code snippet, assuming that description is a String and totalPrice is a double: System.out.printf("%-12s%8.2f",description,totalPrice); Which of the following statements is correct?

This code will produce 2 columns, with the description field left justified and the totalPrice field right justified.

Consider the following code snippet. File inputFile = new File("dataIn.txt"); Scanner in = new Scanner(inputFile); while (in.hasNext()) { String input = in.next(); } Which of the following statements about this code is correct?

This code will read in a word at a time from the input file.

Every class has a toString method and an equals method inherited from the Object class. True/False

True

It is not possible for a superclass to call a subclass's method. True/False

True

14.35 The _________ properties are defined in the javafx.scene.shape.Rectangle class. A. width B. x C. y D. height E. arcWidth

A. width B. x C. y D. height E. arcWidth

The _________ properties are defined in the javafx.scene.shape.Rectangle class. A. width B. x C. y D. height E. arcWidth

A. width B. x C. y D. height E. arcWidth

14.34 The _________ properties are defined in the javafx.scene.shape.Line class. A. x1 B. x2 C. y1 D. y2 E. strikethrough

A. x1 B. x2 C. y1 D. y2

The _________ properties are defined in the javafx.scene.shape.Line class. A. x1 B. x2 C. y1 D. y2 E. strikethrough

A. x1 B. x2 C. y1 D. y2

Which return value of the JFileChooser object's showOpenDialog method indicates that a file was chosen by the user at run time?

APPROVE_OPTION

The PrintWriter class is an enhancement of the ____ class.

PrintStream

Which of the following statements about a PrintWriter object is true?

Data loss may occur if a program fails to close a PrintWriter object before exiting.

What is recommended if the standard library does not have an exception class that describes your particular error situation?

Design your own exception class as a subclass of an existing exception class.

which expression converts the string input containing floating-point digits to its floating-point value?

Double.parseDouble(input)

15.12 Which statement is true about a non-static inner class? A. It must implement an interface. B. It is accessible from any other class. C. It can only be instantiated in the enclosing class. D. It must be final if it is declared in a method scope. E. It can access private instance variables in the enclosing object.

E. It can access private instance variables in the enclosing object.

The method __________ adds an item s into a ComboBox cbo. A. cbo.add(s) B. cbo.addChoice(s) C. cbo.addItem(s) D. cbo.addObject(s) E. cbo.getItems().add(s)

E. cbo.getItems().add(s)

_______________ returns the selected item on a ComboBox cbo. A. cbo.getSelectedIndex() B. cbo.getSelectedItem() C. cbo.getSelectedIndices() D. cbo.getSelectedItems() E. cbo.getValue()

E. cbo.getValue()

which of the following objects should be used for reading from a text file?

Scanner

Which of the following patterns should be used for the delimiter to read one character at a time using a Scanner object's next method?

Scanner in = new Scanner(. . .); in.useDelimiter("");

Consider the following code snippet, assuming that "filename" represents the name of the output file and "writeData" outputs the data to that file:

The "close" method of the "outputFile" object will be automatically invoked when the "try" block ends, whether or not an exception has occurred.

A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final. True/False

True

Which of the following statements about checked and unchecked exceptions is NOT true?

Unchecked exceptions belonging to subclasses of the RunTimeException class are beyond the control of the programmer.

Consider the following code snippet: Scanner in = new Scanner(. . .); while (in.hasNextLine()) { String input = in.nextLine(); System.out.println(input); } Which of the following statements about this code is correct?

This code will read in an entire line from the file in each iteration of the loop.

Consider the following code snippet. Scanner in = new Scanner(. . .); while (in.hasNextDouble()) { double input = in.nextDouble(); } Which of the following statements about this code is correct?

This code will read in one floating point value at a time from the input file.

Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt that resides in a folder named payroll on the C: drive of a Windows system. public static void main(String[] args) throws FileNotFoundException { File inputFile = ________; Scanner in = new Scanner(inputFile); . . . }

new File("c:\\payroll\\dataIn.txt")

Which method of an exception object will retrieve a description of the exception that occurred?

getMessage()

Which method of the JFileChooser object will return the file object that describes the file chosen by the user at runtime?

getSelectedFile()

You wish to use the Scanner class's nextInt() method to read in whole numbers. To avoid exceptions that would occur if the input is not a whole number, you should use the ____ method before calling nextInt().

hasNextInt()

which of the following is correct syntax for starting a Java program named myProg from a command line if the program requires two arguments named "arg1" and "arg2" to be supplied?

java myProg arg1 arg2

Your program will read in an existing text file. You want the program to terminate if the file does not exist. Which of the following indicates the correct code for the main method header?

public static void main(String[] args) throws FileNotFoundException

Your program must read in an existing text file. You want the program to terminate if any exception related to the file occurs. Which of the following indicates the correct code for the header of the main method?

public static void main(String[] args) throws IOException

Which of the following code snippets about exceptions is correct?

public void read(String filename) throws IOException, ClassNotFoundException

Consider the following code snippet, assuming that filename represents the name of the output file and writeData outputs the data to that file: try (PrintWriter outputFile = new PrintWriter(filename)) { writeData(outputFile); } Which of the following statements about this code is correct? You Answered

the close method of the outputFile object will be automatically invoked when the try block ends, whether or not an exception has occurred.

Consider the following code snippet, assuming that "filename" represents the name of the output file and "writeData" outputs the data to that file:

the file will be closed regardless of when an exception occurs.

Consider the following code snippet: public static void main(String[] args) throws IOException Which of the following statements about this code is correct?

the main method terminates if the I0Exception occurs

when writing a method, which of the following statements about exception handling is true?

the throws clause must list all checked exceptions that this method may throw, and may also list unchecked exceptions.

consider the following code snippet: "throw new IllegalArgumentException("This operation is not allowed!"); which of the following statements about this code is correct?

this code constructs an object of type IllegalArgumentException and throws the object.

Consider the following code snippet: public void readFile(String filename) throws FileNotFoundException { File inFile = new File(filename); Scanner in = new Scanner(inFile); . . . } If the file cannot be located, which of the following statements about this code is correct?

this method will be terminated if the file cannot be located

Protected class members are denoted in a UML diagram with the symbol A) # B) - C) + D) *

A) #

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC A) ClassA B) ClassC C) Cannot tell D) ClassB

A) ClassA

When a method is declared with the ________ modifier, it cannot be overridden in a subclass. A) final B) public C) super D) extends

A) final

Which of the following statements about exception reporting is true?

Use the throw statement to report that an exception has occurred.

Assume p is a Polygon, to add a point (4, 5) into p, use _______. A. p.getPoints().add(4); p.getPoints().add(5); B. p.getPoints().add(4.0); p.getPoints().add(5.0); C. p.getPoints().addAll(4, 5); D. p.getPoints().addAll(4.0, 5.0);

B. p.getPoints().add(4.0); p.getPoints().add(5.0); D. p.getPoints().addAll(4.0, 5.0);

14.39 Assume p is a Polygon, to add a point (4, 5) into p, use _______. A. p.getPoints().add(4); p.getPoints().add(5); B. p.getPoints().add(4.0); p.getPoints().add(5.0); C. p.getPoints().addAll(4, 5); D. p.getPoints().addAll(4.0, 5.0);

B. p.getPoints().add(4.0); p.getPoints().add(5.0); D. p.getPoints().addAll(4.0, 5.0);

Insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found. public void String readFile() throws IOException { File inputFile = new File(. . .); try __________________________________ { while (in.hasNext()) { . . . } } }

(Scanner in = new Scanner(inputFile))

15.20 Fill in the code below in the underline: public class Test { public static void main(String[] args) { Test test = new Test(); test.setAction2(______________________________); } public void setAction2(T2 t) { t.m(4.5); } } interface T2 { public void m(Double d); } A. () -> System.out.print(e) B. (e) -> System.out.print(e) C. e -> System.out.print(e) D. (e) -> {System.out.print(e);}

B. (e) -> System.out.print(e) C. e -> System.out.print(e) D. (e) -> {System.out.print(e);}

Which of the following statements about character encodings is NOT true?

Java assumes the UTF-8 encoding.

Create label with text and node

New label(text, node);

Which of the following statements about exception handling is correct?

Statements that may cause an exception should be placed within a try block.

Assume inputFile is a Scanner object used to read data from a text file that contains a series of double values. Select an expression to complete the following code segment, which reads the values and prints them in standard output, one per line, in a field 15 characters wide, with two digits after the decimal point. while (inputFile.hasNextDouble()) { double value = inputFile.nextDouble(); ___________________________________ // statement to display double value }

System.out.printf("%15.2f\n",value);

Consider the following code snippet: public static void main(String[] args) throws FileNotFoundException Which of the following statements about this code is correct?

The main method terminates if the FileNotFoundException occurs.

Consider the following code snippet. String line = ...; Scanner lineScanner = new Scanner(line); Which of the following statements about this code is correct?

The methods of the Scanner class can be used on lineScanner to scan the string.

When writing a method, which of the following statements about exception handling is true?

The throws clause must list all checked exceptions that this method may throw, and may also list unchecked exceptions.

Consider the following code snippet, where data is a variable defined as a double array that is populated by the readData method for valid data: public double[] readInputFile(String filename) throws IOException { try (Scanner in = new Scanner(new File(filename))) { readData(in); return data; } } Which of the following statements about this method's code is correct?

This method will pass any IOException-type exception back to the caller.

which of the following statements about exception handling is recommended?

Throw an exception as soon as a problem is detected, but only catch exceptions when the problem can be handled.

When a subclass extends a superclass, the public members of the superclass become public members of the subclass. True/False

True

You have opened a command prompt window and you have entered the following: java myProg Bob Smith Which of the following statements is correct?

You have supplied two argument values, and these values can be accessed in the main method using the args parameter.

Which of the following statements about reading web pages is true?

You must create a URL object to use with a Scanner object to read a web page.

Select the missing expression in the code fragment below. The method should continue to prompt the user for a valid integer value until one is entered. The method returns the final value entered. public static int getAge() { boolean done = false; Scanner console = new Scanner(System.in); int value = 0; while (!done) { try { System.out.print("Please enter your age in years: "); value = console.nextInt(); done = true; } _____________________ { System.out.println("Invalid value. Try again."); console.nextLine(); } } return value; }

catch (NoSuchElementException exception)

The Java compiler requires that your program handle which type of exceptions?

checked

Insert the missing code in the following code fragment. This fragment is intended to allow the user to select a file to be opened.

chooser.getSelectedFile()

Insert the missing code in the following code fragment. This fragment is intended to allow the user to select a file to be opened. JFileChooser chooser = new JFileChooser(); Scanner in = null; if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File selectedFile = __________; in = new Scanner(selectedFile); . . . }

chooser.getSelectedFile()

Assume inputFile is a Scanner object used to read data from a text file that contains a number of lines. Some lines contain an alphabetic string, while others contain a single integer value. Select an expression to complete the following code segment, which counts the number of integer values in the input file. int count = 0; while (inputFile.hasNextLine()) { if (________________________________) { count++; } inputFile.nextLine(); } System.out.println(count);

inputFile.hasNextInt()

The ____ method of the Character class will indicate if a character contains white space.

isWhiteSpace()

Which command enables assertion checking during program execution?

java -enableassertions MainClass

Consider the following code snippet: Scanner in = new Scanner(. . .); String result = ""; double number = 0; if (in.hasNextDouble()) { number = in.nextDouble(); } result = in.next(); If the input file contains the characters 626.14 average, what values will number and result have after this code is executed?

number will contain the value 626.14 and result will contain the value average.

Consider the following code snippet: "Scanner in = new Scanner(. . .); in.useDelimiter("[^0-9]+"); What characters will be ignored and not read in using this code?

only non-numeric characters will be ignored.

Consider the following code snippet. PrintWriter outputFile = new PrintWriter("payrollReport.txt"); Which of the following statements about the PrintWriter object is correct?

If a file named "payrollReport.txt" already exists, existing data will be deleted before new data are added to the file.

Under which condition will the Scanner constructor generate a FileNotFoundException?

If the input file does not exist.

Which of the following statements about using the PrintWriter object is correct?

If the output file already exists, the existing data will be discarded before new data are written into the file.

When a program throws an exception within a method that has no try-catch block, which of the following statements about exception handling is true?

The current method terminates immediately.

Consider the following code snippet. File hoursFile = new File("hoursWorked.txt"); Your program must read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?

Scanner in = new Scanner(hoursFile);

Which of the following statements about checked and unchecked exceptions is true?

The compiler ensures that the program is handling checked exceptions.

Consider the following code snippet: throw new IllegalArgumentException("This operation is not allowed!"); Which of the following statements about this code is correct?

This code constructs an object of type IllegalArgumentException and throws the object.

Consider the following code snippet: throw IllegalArgumentException("This operation is not allowed!"); Which of the following statements about this code is correct?

This code will not compile.

insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found. String filename = . . .; try (Scanner in = new Scanner(new File(filename))) { . . . } ___________________ { exception.printStackTrace(); }

catch (IOException exception)

which statement about handling exceptions is true?

if an exception has no handler, the program will be terminated

Insert the missing code in the following code fragment. This fragment is intended to read all words from a text file named dataIn.txt. File inputFile = new File("dataIn.txt"); Scanner in = new Scanner(inputFile); while (____________) { String input = in.next(); System.out.println(input); }

in.hasNext()

Insert the missing code in the following code fragment. This fragment is intended to read floating-point numbers from a text file. Scanner in = new Scanner(. . .); while (____________) { double hoursWorked = in.nextDouble(); System.out.println(hoursWorked); }

in.hasNextDouble()

Insert the missing code in the following code fragment. This fragment is intended to read characters from a text file. Scanner in = new Scanner(. . .); in.useDelimiter(""); while (in.hasNext()) { char ch = ____________; System.out.println(ch); }

in.next().charAt(0)

Insert the missing code in the following code fragment. This fragment is intended to read an input file named hoursWorked.txt. You want the program to terminate if the file does not exist. public static void main(String[] args)______________ { File inputFile = new File("hoursWorked.txt"); Scanner in = new Scanner(inputFile); . . . }

throws FileNotFoundException

Select an appropriate expression to complete the header for the method below. public void openFile(String inputFile) ______________________________ { File theFile = new File(inputFile); Scanner data = new Scanner(theFile); // additional statements to input data from file }

throws FileNotFoundException

insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found. public void String readFile() _________________ { File inputFile = new File(. . .); try (Scanner in = new Scanner(inputFile)) { while (in.hasNext()) { . . . } } }

throws I0Exception

Which String class method will remove spaces from the beginning and the end of a string?

trim()

The ______ method of the Scanner class specifies a pattern for word boundaries when reading text.

useDelimiter()

Assume inputFile is a Scanner object used to read data from a text file that contains a number of lines. Each line contains an arbitrary number of words, with at least one word per line. Select an expression to complete the following code segment, which prints the last word in each line. while (inputFile.hasNextLine()) { String word = ""; String line = inputFile.nextLine(); Scanner words = new Scanner(line); while (_________________) { word = words.next(); } System.out.println(word); }

words.hasNextInt()

__________ are properties of ScrollBar. A. value B. min C. max D. orientation E. visibleAmount

A. value B. min C. max D. orientation E. visibleAmount

__________ are properties of ScrollSlider. A. value B. min C. max D. orientation E. visibleAmount

A. value B. min C. max D. orientation E. visibleAmount

What is wrong with the following code? IntCalculator square = new IntCalculator() { public int calculate(int number) { return number + number; }} A) The statement does not end with a semicolon. B) The outer braces are not needed. C) The inner braces are not needed. D) The new key word is not needed.

A) The statement does not end with a semicolon.

15.19 Fill in the code below in the underline: public class Test { public static void main(String[] args) { Test test = new Test(); test.setAction(______________________________); } public void setAction(T1 t) { t.m(); } } interface T1 { public void m(); } A. () -> System.out.print("Action 1! ") B. (e) -> System.out.print("Action 1! ") C. System.out.print("Action 1! ") D. (e) -> {System.out.print("Action 1! ")}

A. () -> System.out.print("Action 1! ")

15.7 Which of the following statements are true? A. A Button can fire an ActionEvent. B. A Button can fire a MouseEvent. C. A Button can fire a KeyEvent. D. A TextField can fire an ActionEvent.

A. A Button can fire an ActionEvent. B. A Button can fire a MouseEvent. C. A Button can fire a KeyEvent. D. A TextField can fire an ActionEvent.

14.19 Which of the following statements are correct? A. A Color object is immutable. B. A Font object is immutable. C. You cannot change the contents in a Color object once it is created. D. You cannot change the contents in a Font object once it is created.

A. A Color object is immutable. B. A Font object is immutable. C. You cannot change the contents in a Color object once it is created. D. You cannot change the contents in a Font object once it is created.

Which of the following statements are correct? A. A Color object is immutable. B. A Font object is immutable. C. You cannot change the contents in a Color object once it is created. D. You cannot change the contents in a Font object once it is created.

A. A Color object is immutable. B. A Font object is immutable. C. You cannot change the contents in a Color object once it is created. D. You cannot change the contents in a Font object once it is created.

Which of the following statements are true? A. A Media can be shared by multiple MediaPlayer. B. A MediaPlayer can be shared by multiple MediaView. C. A MediaView can be placed into multiple Pane. D. A Media can be downloaded from a URL.

A. A Media can be shared by multiple MediaPlayer. B. A MediaPlayer can be shared by multiple MediaView. D. A Media can be downloaded from a URL.

Which of the following statements are true? A. A Node can be placed in a Pane. B. A Node can be placed in a Scene. C. A Pane can be placed in a Control. D. A Shape can be placed in a Control.

A. A Node can be placed in a Pane.

15.8 Which of the following statements are true? A. A Node can fire an ActionEvent. B. A Node can fire a MouseEvent. C. A Node can fire a KeyEvent. D. A Scene can fire a MouseEvent.

A. A Node can fire an ActionEvent. B. A Node can fire a MouseEvent. C. A Node can fire a KeyEvent. D. A Scene can fire a MouseEvent.

Which of the following statements are true? A. A primary stage is automatically created when a JavaFX main class is launched. B. You can have multiple stages displayed in a JavaFX program. C. A stage is displayed by invoking the show() method on the stage. D. A scene is placed in the stage using the addScene method E. A scene is placed in the stage using the setScene method

A. A primary stage is automatically created when a JavaFX main class is launched. B. You can have multiple stages displayed in a JavaFX program. C. A stage is displayed by invoking the show() method on the stage. E. A scene is placed in the stage using the setScene method

15.4 Which of the following are the classes in JavaFX for representing an event? A. ActionEvent B. MouseEvent C. KeyEvent D. WindowEvent

A. ActionEvent B. MouseEvent C. KeyEvent D. WindowEvent

Why is JavaFX preferred? A. JavaFX is much simpler to learn and use for new Java programmers. B. JavaFX provides a multi-touch support for touch-enabled devices such as tablets and smart phones. C. JavaFX has a built-in 3D, animation support, video and audio playback, and runs as a standalone application or from a browser. D. JavaFX incorporates modern GUI technologies to enable you to develop rich Internet applications.

A. JavaFX is much simpler to learn and use for new Java programmers. B. JavaFX provides a multi-touch support for touch-enabled devices such as tablets and smart phones. C. JavaFX has a built-in 3D, animation support, video and audio playback, and runs as a standalone application or from a browser. D. JavaFX incorporates modern GUI technologies to enable you to develop rich Internet applications.

15.13 Which of the following statements are true? A. An anonymous inner class is an inner class without a name. B. An anonymous inner class must always extend a superclass or implement an interface, but it cannot have an explicit extends or implements clause. C. An anonymous inner class must implement all the abstract methods in the superclass or in the interface. D. An anonymous inner class always uses the no-arg constructor from its superclass to create an instance. If an anonymous inner class implements an interface, the constructor is Object(). E. An anonymous inner class is compiled into a class named OuterClassName$n.class.

A. An anonymous inner class is an inner class without a name. B. An anonymous inner class must always extend a superclass or implement an interface, but it cannot have an explicit extends or implements clause. C. An anonymous inner class must implement all the abstract methods in the superclass or in the interface. D. An anonymous inner class always uses the no-arg constructor from its superclass to create an instance. If an anonymous inner class implements an interface, the constructor is Object(). E. An anonymous inner class is compiled into a class named OuterClassName$n.class.

Which of the following statements are true? A. CheckBox inherits from ButtonBase. B. CheckBox inherits from Button. C. CheckBox inherits from Labelled. D. CheckBox inherits from Control. E. CheckBox inherits from Node.

A. CheckBox inherits from ButtonBase. C. CheckBox inherits from Labelled. D. CheckBox inherits from Control. E. CheckBox inherits from Node

Which of the following statements are true? A. ComboBox inherits from ComboBoxBase. B. ComboBox inherits from ButtonBase. C. ComboBox inherits from Labelled. D. ComboBox inherits from Control. E. ComboBox inherits from Node.

A. ComboBox inherits from ComboBoxBase. D. ComboBox inherits from Control. E. ComboBox inherits from Node.

14.9 Which of the following statements are correct? A. Every subclass of Node has a no-arg constructor. B. Circle is a subclass of Node. C. Button is a subclass of Node. D. Pane is a subclass of Node. E. Scene is a subclass on Node.

A. Every subclass of Node has a no-arg constructor. B. Circle is a subclass of Node. C. Button is a subclass of Node. D. Pane is a subclass of Node.

Which of the following statements are correct? A. Every subclass of Node has a no-arg constructor. B. Circle is a subclass of Node. C. Button is a subclass of Node. D. Pane is a subclass of Node. E. Scene is a subclass on Node.

A. Every subclass of Node has a no-arg constructor. B. Circle is a subclass of Node. C. Button is a subclass of Node. D. Pane is a subclass of Node.

15.10 Which of the following statements are true? A. Inner classes can make programs simple and concise. B. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class. C. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class. D. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class.

A. Inner classes can make programs simple and concise. B. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class. C. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class. D. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class.

14.18 Which of the following statements correctly creates a Font object? A. new Font(34); B. new Font("Times", 34); C. Font.font("Times", 34); D. Font.font("Times", FontWeight.NORMAL, 34); E. Font.font("Times", FontWeight.NORMAL, FontPosture.ITALIC, 34);

A. new Font(34); B. new Font("Times", 34); C. Font.font("Times", 34); D. Font.font("Times", FontWeight.NORMAL, 34); E. Font.font("Times", FontWeight.NORMAL, FontPosture.ITALIC, 34);

15.27 Suppose the following program displays a pane in the stage. What is the output if the user presses the key for letter B? import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; // import javafx classes omitted public class Test1 extends Application { @Override public void start(Stage primaryStage) { // Code to create and display pane omitted Pane pane = new Pane(); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage pane.requestFocus(); pane.setOnKeyPressed(e -> System.out.print("Key pressed " + e.getCode() + " ")); pane.setOnKeyTyped(e -> System.out.println("Key typed " + e.getCode())); } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. Key pressed B Key typed UNDEFINED B. Key pressed B Key typed C. Key typed UNDEFINED D. Key pressed B

A. Key pressed B Key typed UNDEFINED

Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { StackPane pane = new StackPane(); Button bt1 = new Button("Java"); Button bt2 = new Button("Java"); Button bt3 = new Button("Java"); Button bt4 = new Button("Java"); pane.getChildren().addAll(bt1, bt2, bt3, bt4); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. One button is displayed with the text "Java". B. Two buttons are displayed with the same text "Java". C. Three buttons are displayed with the same text "Java". D. Four buttons are displayed with the same text "Java".

A. One button is displayed with the text "Java".

Which of the following statements are true? A. PasswordField inherits from TextInputControl. B. PasswordField inherits from TextField. C. PasswordField inherits from Labelled. D. PasswordField inherits from Control. E. PasswordField inherits from Node.

A. PasswordField inherits from TextInputControl. B. PasswordField inherits from TextField. D. PasswordField inherits from Control. E. PasswordField inherits from Node.

15.35 __________ is a subclass of Animation. A. PathTransition B. FadeTransition C. Timeline D. Duration

A. PathTransition B. FadeTransition C. Timeline

Which of the following statements are true? A. RadioButton inherits from ButtonBase. B. RadioButton inherits from Button. C. RadioButton inherits from Labelled. D. RadioButton inherits from Control. E. RadioButton inherits from Node.

A. RadioButton inherits from ButtonBase. C. RadioButton inherits from Labelled. D. RadioButton inherits from Control. E. RadioButton inherits from Node.

Which of the following statements are true? A. TextArea inherits from TextInputControl. B. TextArea inherits from TextField. C. TextArea inherits from Labelled. D. TextArea inherits from Control. E. TextArea inherits from Node.

A. TextArea inherits from TextInputControl. D. TextArea inherits from Control. E. TextArea inherits from Node.

Which of the following statements are true? A. TextField inherits from TextInputControl. B. TextField inherits from ButtonBase. C. TextField inherits from Labelled. D. TextField inherits from Control. E. TextField inherits from Node.

A. TextField inherits from TextInputControl. D. TextField inherits from Control. E. TextField inherits from Node.

14.31 Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.layout.HBox; import javafx.scene.shape.Circle; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { HBox pane = new HBox(5); Circle circle = new Circle(50, 200, 200); pane.getChildren().addAll(circle); circle.setCenterX(100); circle.setCenterY(100); circle.setRadius(50); pane.getChildren().addAll(circle); // Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. The program has a compile error since the circle is added to a pane twice. B. The program has a runtime error since the circle is added to a pane twice. C. The program runs fine and displays one circle. D. The program runs fine and displays two circles.

A. The program has a compile error since the circle is added to a pane twice.

The _________ properties are defined in the javafx.scene.text.Text class. A. text B. x C. y D. underline E. strikethrough

A. text B. x C. y D. underline E. strikethrough

You can use the _________ properties in a ComboBox. A. value B. editable C. onAction D. items E. visibleRowCount

A. value B. editable C. onAction D. items E. visibleRowCount

Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.layout.HBox; import javafx.scene.shape.Circle; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { HBox pane = new HBox(5); Circle circle = new Circle(50, 200, 200); pane.getChildren().addAll(circle); circle.setCenterX(100); circle.setCenterY(100); circle.setRadius(50); pane.getChildren().addAll(circle); // Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. The program has a compile error since the circle is added to a pane twice. B. The program has a runtime error since the circle is added to a pane twice. C. The program runs fine and displays one circle. D. The program runs fine and displays two circles.

A. The program has a compile error since the circle is added to a pane twice.

Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { HBox pane = new HBox(5); Image usIcon = new Image("http://www.cs.armstrong.edu/liang/image/usIcon.gif"); Button bt1 = new Button("Button1", new ImageView(usIcon)); Button bt2 = new Button("Button2", new ImageView(usIcon)); pane.getChildren().addAll(bt1, bt2); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. Two buttons displayed with the same icon. B. Only bt2 displays the icon and bt1 does not display the icon. C. Only bt1 displays the icon and bt2 does not display the icon. D. Two buttons displayed with different icons.

A. Two buttons displayed with the same icon.

15.16 Analyze the following code. import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); Button btCancel = new Button("Cancel"); EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }; btOK.setOnAction(handler); btCancel.setOnAction(handler); HBox pane = new HBox(5); pane.getChildren().addAll(btOK, btCancel); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. When clicking the OK button, the program displays The OK button is clicked. B. When clicking the Cancel button, the program displays The OK button is clicked. C. When clicking either button, the program displays The OK button is clicked twice. D. The program has a runtime error, because the handler is registered with more than one source.

A. When clicking the OK button, the program displays The OK button is clicked. B. When clicking the Cancel button, the program displays The OK button is clicked.

Which of the following statements are true? A. You can specify a horizontal text alignment in a text field. B. You can specify the number of columns in a text field. C. You can disable editing on a text field. D. You can create a text field with a specified text.

A. You can specify a horizontal text alignment in a text field. B. You can specify the number of columns in a text field. C. You can disable editing on a text field. D. You can create a text field with a specified text.

__________ are properties in Labelled. A. alignment B. contentDisplay C. graphic D. text E. underline

A. alignment B. contentDisplay C. graphic D. text E. underline

You can use the properties _________ to control a MediaPlayer. A. autoPlay B. currentCount C. cycleCount D. mute E. volume

A. autoPlay B. currentCount C. cycleCount D. mute E. volume

15.31 The properties _________ are defined in the Animation class. A. autoReverse B. cycleCount C. rate D. status

A. autoReverse B. cycleCount C. rate D. status

15.18 Which of the following code correctly registers a handler with a button btOK? A. btOK.setOnAction(e -> System.out.println("Handle the event")); B. btOK.setOnAction((e) -> System.out.println("Handle the event");); C. btOK.setOnAction((ActionEvent e) -> System.out.println("Handle the event")); D. btOK.setOnAction(e -> {System.out.println("Handle the event");});

A. btOK.setOnAction(e -> System.out.println("Handle the event")); B. btOK.setOnAction((e) -> System.out.println("Handle the event");); C. btOK.setOnAction((ActionEvent e) -> System.out.println("Handle the event")); D. btOK.setOnAction(e -> {System.out.println("Handle the event");});

14.36 The _________ properties are defined in the javafx.scene.shape.Ellipse class. A. centerX B. centerY C. radiusX D. radiusY

A. centerX B. centerY C. radiusX D. radiusY

The _________ properties are defined in the javafx.scene.shape.Ellipse class. A. centerX B. centerY C. radiusX D. radiusY

A. centerX B. centerY C. radiusX D. radiusY

14.15 Which of the following statements correctly sets the fill color of circle to black? A. circle.setFill(Color.BLACK); B. circle.setFill(Color.black); C. circle.setStyle("-fx-fill: black"); D. circle.setStyle("fill: black"); E. circle.setStyle("-fx-fill-color: black");

A. circle.setFill(Color.BLACK); C. circle.setStyle("-fx-fill: black");

Which of the following statements correctly sets the fill color of circle to black? A. circle.setFill(Color.BLACK); B. circle.setFill(Color.black); C. circle.setStyle("-fx-fill: black"); D. circle.setStyle("fill: black"); E. circle.setStyle("-fx-fill-color: black");

A. circle.setFill(Color.BLACK); C. circle.setStyle("-fx-fill: black");

14.13 What is the output of the following code? import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; public class Test { public static void main(String[] args) { IntegerProperty d1 = new SimpleIntegerProperty(1); IntegerProperty d2 = new SimpleIntegerProperty(2); d1.bind(d2); System.out.print("d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); d2.setValue(3); System.out.println(", d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); } } A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3 B. d1 is 2 and d2 is 2, d1 is 2 and d2 is 3 C. d1 is 1 and d2 is 2, d1 is 1 and d2 is 3 D. d1 is 1 and d2 is 2, d1 is 3 and d2 is 3

A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3

14.14 What is the output of the following code? import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; public class Test { public static void main(String[] args) { IntegerProperty d1 = new SimpleIntegerProperty(1); IntegerProperty d2 = new SimpleIntegerProperty(2); d1.bindBidirectional(d2); System.out.print("d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); d1.setValue(3); System.out.println(", d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); } } A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3 B. d1 is 2 and d2 is 2, d1 is 2 and d2 is 3 C. d1 is 1 and d2 is 2, d1 is 1 and d2 is 3 D. d1 is 1 and d2 is 2, d1 is 3 and d2 is 3

A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3

What is the output of the following code? import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; public class Test { public static void main(String[] args) { IntegerProperty d1 = new SimpleIntegerProperty(1); IntegerProperty d2 = new SimpleIntegerProperty(2); d1.bind(d2); System.out.print("d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); d2.setValue(3); System.out.println(", d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); } } A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3 B. d1 is 2 and d2 is 2, d1 is 2 and d2 is 3 C. d1 is 1 and d2 is 2, d1 is 1 and d2 is 3 D. d1 is 1 and d2 is 2, d1 is 3 and d2 is 3

A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3

What is the output of the following code? import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; public class Test { public static void main(String[] args) { IntegerProperty d1 = new SimpleIntegerProperty(1); IntegerProperty d2 = new SimpleIntegerProperty(2); d1.bindBidirectional(d2); System.out.print("d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); d1.setValue(3); System.out.println(", d1 is " + d1.getValue() + " and d2 is " + d2.getValue()); } } A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3 B. d1 is 2 and d2 is 2, d1 is 2 and d2 is 3 C. d1 is 1 and d2 is 2, d1 is 1 and d2 is 3 D. d1 is 1 and d2 is 2, d1 is 3 and d2 is 3

A. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3

15.33 To properties _________ are defined in the FadeTransition class. A. duration B. node C. fromValue D. toValue E. byValue

A. duration B. node C. fromValue D. toValue E. byValue

15.32 The properties _________ are defined in the PathTransition class. A. duration B. node C. orientation D. path

A. duration B. node C. orientation D. path

____________ are properties for a ListView. A. items B. orientation C. selectionModel D. visibleRowCount E. onAction

A. items B. orientation C. selectionModel

14.26 Which of the following statements are correct to create a FlowPane? A. new FlowPane() B. new FlowPane(4, 5) C. new FlowPane(Orientation.VERTICAL); D. new FlowPane(4, 5, Orientation.VERTICAL);

A. new FlowPane() B. new FlowPane(4, 5) C. new FlowPane(Orientation.VERTICAL); D. new FlowPane(4, 5, Orientation.VERTICAL);

Which of the following statements are correct to create a FlowPane? A. new FlowPane() B. new FlowPane(4, 5) C. new FlowPane(Orientation.VERTICAL); D. new FlowPane(4, 5, Orientation.VERTICAL);

A. new FlowPane() B. new FlowPane(4, 5) C. new FlowPane(Orientation.VERTICAL); D. new FlowPane(4, 5, Orientation.VERTICAL);

Which of the following statements correctly creates a Font object? A. new Font(34); B. new Font("Times", 34); C. Font.font("Times", 34); D. Font.font("Times", FontWeight.NORMAL, 34); E. Font.font("Times", FontWeight.NORMAL, FontPosture.ITALIC, 34);

A. new Font(34); B. new Font("Times", 34); C. Font.font("Times", 34); D. Font.font("Times", FontWeight.NORMAL, 34); E. Font.font("Times", FontWeight.NORMAL, FontPosture.ITALIC, 34);

14.20 Which of the following statements correctly creates an ImageView object? A. new ImageView("http://www.cs.armstrong.edu/liang/image/us.gif"); B. new ImageView(new Image("http://www.cs.armstrong.edu/liang/image/us.gif")); C. new ImageView("image/us.gif"); D. new ImageView(new Image("image/us.gif"));

A. new ImageView("http://www.cs.armstrong.edu/liang/image/us.gif"); B. new ImageView(new Image("http://www.cs.armstrong.edu/liang/image/us.gif")); C. new ImageView("image/us.gif"); D. new ImageView(new Image("image/us.gif"));

Which of the following statements correctly creates an ImageView object? A. new ImageView("http://www.cs.armstrong.edu/liang/image/us.gif"); B. new ImageView(new Image("http://www.cs.armstrong.edu/liang/image/us.gif")); C. new ImageView("image/us.gif"); D. new ImageView(new Image("image/us.gif"));

A. new ImageView("http://www.cs.armstrong.edu/liang/image/us.gif"); B. new ImageView(new Image("http://www.cs.armstrong.edu/liang/image/us.gif")); C. new ImageView("image/us.gif"); D. new ImageView(new Image("image/us.gif"));

14.37 To construct a Polygon with three points x1, y1, x2, y2, x3, and y3, use _________. A. new Polygon(x1, y1, x2, y2, x3, y3) B. new Polygon(x1, y2, x3, y1, y2, y3) C. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y1, x2, y2, x3, y3) D. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y2, x3, y1, y2, y3)

A. new Polygon(x1, y1, x2, y2, x3, y3) C. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y1, x2, y2, x3, y3)

To construct a Polygon with three points x1, y1, x2, y2, x3, and y3, use _________. A. new Polygon(x1, y1, x2, y2, x3, y3) B. new Polygon(x1, y2, x3, y1, y2, y3) C. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y1, x2, y2, x3, y3) D. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y2, x3, y1, y2, y3)

A. new Polygon(x1, y1, x2, y2, x3, y3) C. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y1, x2, y2, x3, y3)

14.38 To construct a Polyline with three points x1, y1, x2, y2, x3, and y3, use _________. A. new Polyline(x1, y1, x2, y2, x3, y3) B. new Polyline(x1, y2, x3, y1, y2, y3) C. Polyline polyline = new Polygon(); polyline.getPoints().addAll(x1, y1, x2, y2, x3, y3) D. Polyline polyline = new Polygon(); polyline.getPoints().addAll(x1, y2, x3, y1, y2, y3)

A. new Polyline(x1, y1, x2, y2, x3, y3) C. Polyline polyline = new Polygon(); polyline.getPoints().addAll(x1, y1, x2, y2, x3, y3)

To construct a Polyline with three points x1, y1, x2, y2, x3, and y3, use _________. A. new Polyline(x1, y1, x2, y2, x3, y3) B. new Polyline(x1, y2, x3, y1, y2, y3) C. Polyline polyline = new Polygon(); polyline.getPoints().addAll(x1, y1, x2, y2, x3, y3) D. Polyline polyline = new Polygon(); polyline.getPoints().addAll(x1, y2, x3, y1, y2, y3)

A. new Polyline(x1, y1, x2, y2, x3, y3) C. Polyline polyline = new Polygon(); polyline.getPoints().addAll(x1, y1, x2, y2, x3, y3)

Which of the following statements are correct? A. new Scene(new Button("OK")); B. new Scene(new Circle()); C. new Scene(new ImageView()); D. new Scene(new Pane());

A. new Scene(new Button("OK")); D. new Scene(new Pane());

15.23 To handle the mouse click event on a pane p, register the handler with p using ______. A. p.setOnMouseClicked(handler); B. p.setOnMouseDragged(handler); C. p.setOnMouseReleased(handler); D. p.setOnMousePressed(handler);

A. p.setOnMouseClicked(handler);

14.28 To add two nodes node1 and node2 to the the first row in a GridPane pane, use ________. A. pane.add(node1, 0, 0); pane.add(node2, 1, 0); B. pane.add(node1, node2, 0); C. pane.addRow(0, node1, node2); D. pane.addRow(1, node1, node2); E. pane.add(node1, 0, 1); pane.add(node2, 1, 1);

A. pane.add(node1, 0, 0); pane.add(node2, 1, 0); C. pane.addRow(0, node1, node2);

To add two nodes node1 and node2 to the the first row in a GridPane pane, use ________. A. pane.add(node1, 0, 0); pane.add(node2, 1, 0); B. pane.add(node1, node2, 0); C. pane.addRow(0, node1, node2); D. pane.addRow(1, node1, node2); E. pane.add(node1, 0, 1); pane.add(node2, 1, 1);

A. pane.add(node1, 0, 0); pane.add(node2, 1, 0); C. pane.addRow(0, node1, node2);

14.12 Suppose a JavaFX class has a binding property named weight of the type DoubleProperty. By convention, which of the following methods are defined in the class? A. public double getWeight() B. public void setWeight(double v) C. public DoubleProperty weightProperty() D. public double weightProperty() E. public DoubleProperty WeightProperty()

A. public double getWeight() B. public void setWeight(double v) C. public DoubleProperty weightProperty()

Suppose a JavaFX class has a binding property named weight of the type DoubleProperty. By convention, which of the following methods are defined in the class? A. public double getWeight() B. public void setWeight(double v) C. public DoubleProperty weightProperty() D. public double weightProperty() E. public DoubleProperty WeightProperty()

A. public double getWeight() B. public void setWeight(double v) C. public DoubleProperty weightProperty()

14.32 The _________ properties are defined in the javafx.scene.shape.Shape class. A. stroke B. strokeWidth C. fill D. centerX

A. stroke B. strokeWidth C. fill

The _________ properties are defined in the javafx.scene.shape.Shape class. A. stroke B. strokeWidth C. fill D. centerX

A. stroke B. strokeWidth C. fill

14.33 The _________ properties are defined in the javafx.scene.text.Text class. A. text B. x C. y D. underline E. strikethrough

A. text B. x C. y D. underline E. strikethrough

The properties ___________ can be used in a TextField. A. text B. editable C. alignment D. prefColumnCount E. onAction

A. text B. editable C. alignment D. prefColumnCount E. onAction

Which of the following statements about assertion is NOT true?

An assertion is always checked during program execution

Consider the following code snippet: Scanner in = new Scanner(. . .); int ageValue = in.nextInt(); If there is no integer number appearing next in the input, what will occur?

An exception will occur

15.21 Fill in the code below in the underline: public class Test { public static void main(String[] args) { Test test = new Test(); System.out.println(test.setAction3(_____________)); } public double setAction3(T3 t) { return t.m(5.5); } } interface T3 { public double m(Double d); } A. () -> e * 2 B. (e) -> e * 2 C. e -> e * 2 D. (e) -> {e * 2;}

B. (e) -> e * 2 C. e -> e * 2

15.26 Fill in the code to display the key pressed in the text. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.text.Text; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Pane pane = new Pane(); Text text = new Text(20, 20, "Welcome"); pane.getChildren().add(text); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage text.setFocusTraversable(true); text.setOnKeyPressed(_______________________); } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. () -> text.setText(e.getText()) B. (e) -> text.setText(e.getText()) C. e -> text.setText(e.getText()) D. e -> {text.setText(e.getText());}

B. (e) -> text.setText(e.getText()) C. e -> text.setText(e.getText()) D. e -> {text.setText(e.getText());}

How many items can be selected from a ComboBox at a time? A. 0 B. 1 C. 2 D. Unlimited

B. 1

15.9 Which of the following statements are true? A. A Shape can fire an ActionEvent. B. A Shape can fire a MouseEvent. C. A Shape can fire a KeyEvent. D. A Text is a Shape. E. A Circle is a Shape.

B. A Shape can fire a MouseEvent. C. A Shape can fire a KeyEvent. D. A Text is a Shape. E. A Circle is a Shape.

Which of the following statements are true? A. A Scene is a Node. B. A Shape is a Node. C. A Stage is a Node. D. A Control is a Node. E. A Pane is a Node.

B. A Shape is a Node. D. A Control is a Node. E. A Pane is a Node.

15.6 Which of the following statements are true? A. A handler object fires an event. B. A source object fires an event. C. Any object such a String object can fire an event. D. A handler is registered with the source object for processing the event.

B. A source object fires an event. D. A handler is registered with the source object for processing the event.

__________ is a superclass for Button. A. Label B. Labelled C. ButtonBase D. Control E. Node

B. Labelled C. ButtonBase D. Control E. Node

__________ is a superclass for Label. A. Scene B. Labelled C. ButtonBase D. Control E. Node

B. Labelled D. Control E. Node

15.11 Suppose A is an inner class in Test. A is compiled into a file named _________. A. A.class B. Test$A.class C. A$Test.class D. Test&A.class

B. Test$A.class

15.29 Analyze the following code: import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleDoubleProperty; public class Test { public static void main(String[] args) { DoubleProperty balance = new SimpleDoubleProperty(); balance.addListener(ov -> System.out.println(2 + balance.doubleValue())); balance.set(4.5); } } A. The program displays 4.5. B. The program displays 6.5. C. The program would display 4.5 if the balance.set(4.5) is placed before the balance.addListener(...) statement. D. The program would display 6.5 if the balance.set(4.5) is placed before the balance.addListener(...) statement.

B. The program displays 6.5.

15.22 Analyze the following code: public class Test { public static void main(String[] args) { Test test = new Test(); test.setAction(() -> System.out.print("Action 1! ")); } public void setAction(T t) { t.m1(); } } interface T { public void m1(); public void m2(); } A. The program displays Action 1. B. The program has a compile error because T is not a functional interface. T contains multiple methods. C. The program would work if you delete the method m2 from the interface T. D. The program has a runtime error because T is not a functional interface. T contains multiple methods.

B. The program has a compile error because T is not a functional interface. T contains multiple methods. C. The program would work if you delete the method m2 from the interface T.

15.1 A JavaFX action event handler is an instance of _______. A. ActionEvent B. Action C. EventHandler D. EventHandler<ActionEvent>

D. EventHandler<ActionEvent>

Which of the following statements are true? A. You can specify a horizontal text alignment in a text area. B. You can specify the number of columns in a text area. C. You can disable editing on a text area. D. You can create a text field with a specified text area. E. You can specify the number of rows in a text area.

B. You can specify the number of columns in a text area. C. You can disable editing on a text area. D. You can create a text field with a specified text area. E. You can specify the number of rows in a text area.

Every JavaFX main class __________. A. implements javafx.application.Application B. extends javafx.application.Application C. overrides start(Stage s) method D. overrides start() method

B. extends javafx.application.Application C. overrides start(Stage s) method

To wrap a line in a text area jta on words, invoke ____________. A. jta.setWrapStyleWord(false) B. jta.setWrapStyleWord(true) C. jta.wrapStyleWord() D. jta.wrapWord()

B. jta.setWrapStyleWord(true)

14.17 Which of the following statements correctly creates a Color object? A. new Color(3, 5, 5, 1); B. new Color(0.3, 0.5, 0.5, 0.1); C. new Color(0.3, 0.5, 0.5); D. Color.color(0.3, 0.5, 0.5); E. Color.color(0.3, 0.5, 0.5, 0.1);

B. new Color(0.3, 0.5, 0.5, 0.1); D. Color.color(0.3, 0.5, 0.5); E. Color.color(0.3, 0.5, 0.5, 0.1);

Which of the following statements correctly creates a Color object? A. new Color(3, 5, 5, 1); B. new Color(0.3, 0.5, 0.5, 0.1); C. new Color(0.3, 0.5, 0.5); D. Color.color(0.3, 0.5, 0.5); E. Color.color(0.3, 0.5, 0.5, 0.1);

B. new Color(0.3, 0.5, 0.5, 0.1); D. Color.color(0.3, 0.5, 0.5); E. Color.color(0.3, 0.5, 0.5, 0.1);

14.21 Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.image.Image; import javafx.scene.image.ImageView; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane to hold the image views Pane pane = new HBox(10); pane.setPadding(new Insets(5, 5, 5, 5)); Image image = new Image("www.cs.armstrong.edu/liang/image/us.gif"); pane.getChildren().addAll(new ImageView(image), new ImageView(image)); // Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle("ShowImage"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. The program runs fine and displays two images. B. new Image("www.cs.armstrong.edu/liang/image/us.gif") must be replaced by new Image("http://www.cs.armstrong.edu/liang/image/us.gif"). C. The image object cannot be shared by two ImageViews. D. The addAll method needs to be replaced by the add method.

B. new Image("www.cs.armstrong.edu/liang/image/us.gif") must be replaced by new Image("http://www.cs.armstrong.edu/liang/image/us.gif").

Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.image.Image; import javafx.scene.image.ImageView; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane to hold the image views Pane pane = new HBox(10); pane.setPadding(new Insets(5, 5, 5, 5)); Image image = new Image("www.cs.armstrong.edu/liang/image/us.gif"); pane.getChildren().addAll(new ImageView(image), new ImageView(image)); // Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle("ShowImage"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. The program runs fine and displays two images. B. new Image("www.cs.armstrong.edu/liang/image/us.gif") must be replaced by new Image("http://www.cs.armstrong.edu/liang/image/us.gif"). C. The image object cannot be shared by two ImageViews. D. The addAll method needs to be replaced by the add method.

B. new Image("www.cs.armstrong.edu/liang/image/us.gif") must be replaced by new Image("http://www.cs.armstrong.edu/liang/image/us.gif").

15.5 To register a source for an action event with a handler, use __________. A. source.addAction(handler) B. source.setOnAction(handler) C. source.addOnAction(handler) D. source.setActionHandler(handler)

B. source.setOnAction(handler)

The method __________ appends a string s into the text area ta. A. ta.setText(s) B. ta.appendText(s) C. ta.append(s) D. ta.insertText(s)

B. ta.appendText(s)

The method __________ gets the contents of the text field tf. A. tf.getText(s) B. tf.getText() C. tf.getString() D. tf.findString()

B. tf.getText()

Which of the following statements reflects the recommendations about closing files?

Both the input and the output file should be explicitly closed in the program.

14.10 Which of the following are binding properties? A. Integer B. Double C. IntegerProperty D. DoubleProperty E. String

C. IntegerProperty D. DoubleProperty

14.11 Which of the following can be used as a source for binding properties? A. Integer B. Double C. IntegerProperty D. DoubleProperty E. String

C. IntegerProperty D. DoubleProperty

Which of the following are binding properties? A. Integer B. Double C. IntegerProperty D. DoubleProperty E. String

C. IntegerProperty D. DoubleProperty

Which of the following can be used as a source for a binding properties? A. Integer B. Double C. IntegerProperty D. DoubleProperty E. String

C. IntegerProperty D. DoubleProperty

15.15 Analyze the following code. import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); btOK.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. The program has a compile error because no handlers are registered with btOK. B. The program has a runtime error because no handlers are registered with btOK. C. The message "The OK button is clicked" is displayed when you click the OK button. D. The handle method is not executed when you click the OK button, because no handler is registered with btOK.

C. The message "The OK button is clicked" is displayed when you click the OK button.

Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.RadioButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.FlowPane; import javafx.scene.layout.Pane; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Pane pane = new FlowPane(); ToggleGroup group = new ToggleGroup(); RadioButton rb1 = new RadioButton("Java"); RadioButton rb2 = new RadioButton("C++"); pane.getChildren().addAll(rb1, rb2); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. The program displays two radio buttons. The two radio buttons are grouped. B. The program displays one radio button with text Java. C. The program displays two radio buttons. The two radio buttons are not grouped. D. The program displays one radio button with text C++.

C. The program displays two radio buttons. The two radio buttons are not grouped.

15.3 A JavaFX event handler for event type T is an instance of _______. A. ActionEvent B. Action C. EventHandler D. EventHandler<T>

D. EventHandler<T>

To remove two nodes node1 and node2 from a pane, use ______. A. pane.remove(node1, node2); B. pane.removeAll(node1, node2); C. pane.getChildren().remove(node1, node2); D. pane.getChildren().removeAll(node1, node2);

D. pane.getChildren().removeAll(node1, node2);

15.17 Analyze the following code. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a button and place it in the scene Button btOK = new Button("OK"); btOK.setOnAction(e -> System.out.println("OK 1")); btOK.setOnAction(e -> System.out.println("OK 2")); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. When clicking the button, the program displays OK1 OK2. B. When clicking the button, the program displays OK1. C. When clicking the button, the program displays OK2. D. The program has a compile error, because the setOnAction method is invoked twice.

C. When clicking the button, the program displays OK2.

14.16 Which of the following statements correctly rotates the button 45 degrees counterclockwise? A. button.setRotate(45); B. button.setRotate(Math.toRadians(45)); C. button.setRotate(360 - 45); D. button.setRotate(-45);

C. button.setRotate(360 - 45); D. button.setRotate(-45);

Which of the following statements correctly rotates the button 45 degrees counterclockwise? A. button.setRotate(45); B. button.setRotate(Math.toRadians(45)); C. button.setRotate(360 - 45); D. button.setRotate(-45)

C. button.setRotate(360 - 45); D. button.setRotate(-45);

_________ checks whether the CheckBox chk is selected. A. chk.getSelected() B. chk.selected() C. chk.isSelected(). D. chk.select()

C. chk.isSelected().

The statement for registering a listener for processing list view item change is ___________. A. lv.getItems().addListener(e -> {processStatements}); B. lv.addListener(e -> {processStatements}); C. lv.getSelectionModel().selectedItemProperty().addListener(e -> {processStatements}); D. lv.getSelectionModel().addListener(e -> {processStatements});

C. lv.getSelectionModel().selectedItemProperty().addListener(e -> {processStatements});

15.34 To create a KeyFrame with duration 1 second, use ______________. A. new KeyFrame(1000, handler) B. new KeyFrame(1, handler) C. new KeyFrame(Duration.millis(1000), handler) D. new KeyFrame(Duration.seconds(1), handler)

C. new KeyFrame(Duration.millis(1000), handler) D. new KeyFrame(Duration.seconds(1), handler)

14.29 To place a node in the left of a BorderPane p, use ___________. A. p.setEast(node); B. p.placeLeft(node); C. p.setLeft(node); D. p.left(node);

C. p.setLeft(node);

14.22 To add a node into a pane, use ______. A. pane.add(node); B. pane.addAll(node); C. pane.getChildren().add(node); D. pane.getChildren().addAll(node);

C. pane.getChildren().add(node); D. pane.getChildren().addAll(node);

To add a node into a pane, use ______. A. pane.add(node); B. pane.addAll(node); C. pane.getChildren().add(node); D. pane.getChildren().addAll(node);

C. pane.getChildren().add(node); D. pane.getChildren().addAll(node);

14.24 To remove a node from the pane, use ______. A. pane.remove(node); B. pane.removeAll(node); C. pane.getChildren().remove(node); D. pane.getChildren().removeAll(node);

C. pane.getChildren().remove(node); D. pane.getChildren().removeAll(node);

To remove a node from the pane, use ______. A. pane.remove(node); B. pane.removeAll(node); C. pane.getChildren().remove(node); D. pane.getChildren().removeAll(node)

C. pane.getChildren().remove(node); D. pane.getChildren().removeAll(node);

15.24 Fill in the code in the underlined location to display the mouse point location when the mouse is pressed in the pane. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Pane pane = new Pane(); ______________________________________ Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. pane.setOnMouseClicked((e) -> System.out.println(e.getX() + ", " + e.getY())); B. pane.setOnMouseReleased(e -> {System.out.println(e.getX() + ", " + e.getY())}); C. pane.setOnMousePressed(e -> System.out.println(e.getX() + ", " + e.getY())); D. pane.setOnMouseDragged((e) -> System.out.println(e.getX() + ", " + e.getY()));

C. pane.setOnMousePressed(e -> System.out.println(e.getX() + ", " + e.getY()));

14.25 To remove two nodes node1 and node2 from a pane, use ______. A. pane.remove(node1, node2); B. pane.removeAll(node1, node2); C. pane.getChildren().remove(node1, node2); D. pane.getChildren().removeAll(node1, node2);

D. pane.getChildren().removeAll(node1, node2);

You can use the methods _________ to control a MediaPlayer. A. start(). B. stop(). C. pause(). D. play().

C. pause(). D. play().

15.2 A JavaFX action event handler contains a method ________. A. public void actionPerformed(ActionEvent e) B. public void actionPerformed(Event e) C. public void handle(ActionEvent e) D. public void handle(Event e)

C. public void handle(ActionEvent e)

_________ checks whether the RadioButton rb is selected. A. rb.getSelected() B. rb.selected() C. rb.isSelected(). D. rb.select()

C. rb.isSelected().

The statement for registering a listener for processing scroll bar value change is ___________. A. sb.addListener(e -> {processStatements}); B. sb.getValue().addListener(e -> {processStatements}); C. sb.valueProperty().addListener(e -> {processStatements}); D. sb.getItems().addListener(e -> {processStatements});

C. sb.valueProperty().addListener(e -> {processStatements});

The statement for registering a listener for processing slider change is ___________. A. sl.addListener(e -> {processStatements}); B. sl.getValue().addListener(e -> {processStatements}); C. sl.valueProperty().addListener(e -> {processStatements}); D. sl.getItems().addListener(e -> {processStatements});

C. sl.valueProperty().addListener(e -> {processStatements});

Which of the following statements about command line arguments is correct?

Command line arguments can be read using the main method's args parameter.

The setOnAction method is defined in _________. A. Label B. Labelled C. Node D. ButtonBase E. Button

D. ButtonBase

Analyze the following code: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.Pane; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Pane pane = new FlowPane(); Button bt1 = new Button("Java"); Button bt2 = new Button("Java"); Button bt3 = new Button("Java"); Button bt4 = new Button("Java"); pane.getChildren().addAll(bt1, bt2, bt3, bt4); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. One button is displayed with the text "Java". B. Two buttons are displayed with the same text "Java". C. Three buttons are displayed with the same text "Java". D. Four buttons are displayed with the same text "Java".

D. Four buttons are displayed with the same text "Java".

15.28 Suppose the follwoing program displays a pane in the stage. What is the output if the user presses the DOWN arrow key? import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; // import javafx classes omitted public class Test1 extends Application { @Override public void start(Stage primaryStage) { // Code to create and display pane omitted Pane pane = new Pane(); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage pane.requestFocus(); pane.setOnKeyPressed(e -> System.out.print("Key pressed " + e.getCode() + " ")); pane.setOnKeyTyped(e -> System.out.println("Key typed " + e.getCode())); } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. Key pressed DOWN Key typed UNDEFINED B. Key pressed DOWN Key typed C. Key typed UNDEFINED D. Key pressed DOWN

D. Key pressed DOWN

Which of the following statements are true? A. ListView inherits from ComboBoxBase. B. ListView inherits from ButtonBase. C. ListView inherits from Labelled. D. ListView inherits from Control. E. ListView inherits from Node.

D. ListView inherits from Control. E. ListView inherits from Node.

15.14 Suppose A is an anonymous inner class in Test. A is compiled into a file named _________. A. A.class B. Test$A.class C. A$Test.class D. Test$1.class E. Test&1.class

D. Test$1.class

How many items can be added into a ComboBox object? A. 0 B. 1 C. 2 D. Unlimited

D. Unlimited

To set the node to the right of the text in a label lbl, use _______. A. lbl.setContentDisplay(ContentDisplay.TOP); B. lbl.setContentDisplay(ContentDisplay.BOTTOM); C. lbl.setContentDisplay(ContentDisplay.LEFT); D. lbl.setContentDisplay(ContentDisplay.RIGHT);

D. lbl.setContentDisplay(ContentDisplay.RIGHT);

To set a red color for the text in the label lbl, use _________. A. lbl.setFill(Color.red); B. lbl.setTextFill(Color.red); C. lbl.setFill(Color.RED); D. lbl.setTextFill(Color.RED);

D. lbl.setTextFill(Color.RED);

To create a label with the specified text, use __________. A. new Labelled(); B. new Label(); C. new Labelled(text); D. new Label(text);

D. new Label(text);

14.30 To place two nodes node1 and node2 in a HBox p, use ___________. A. p.add(node1, node2); B. p.addAll(node1, node2); C. p.getChildren().add(node1, node2); D. p.getChildren().addAll(node1, node2);

D. p.getChildren().addAll(node1, node2);

To place two nodes node1 and node2 in a HBox p, use ___________. A. p.add(node1, node2); B. p.addAll(node1, node2); C. p.getChildren().add(node1, node2); D. p.getChildren().addAll(node1, node2);

D. p.getChildren().addAll(node1, node2);

15.25 To handle the key pressed event on a pane p, register the handler with p using ______. A. p.setOnKeyClicked(handler); B. p.setOnKeyTyped(handler); C. p.setOnKeyReleased(handler); D. p.setOnKeyPressed(handler);

D. p.setOnKeyPressed(handler);

14.23 To add two nodes node1 and node2 into a pane, use ______. A. pane.add(node1, node2); B. pane.addAll(node1, node2); C. pane.getChildren().add(node1, node2); D. pane.getChildren().addAll(node1, node2);

D. pane.getChildren().addAll(node1, node2);

To add two nodes node1 and node2 into a pane, use ______. A. pane.add(node1, node2); B. pane.addAll(node1, node2); C. pane.getChildren().add(node1, node2); D. pane.getChildren().addAll(node1, node2);

D. pane.getChildren().addAll(node1, node2);

What is the output of the following JavaFX program? import javafx.application.Application; import javafx.stage.Stage; public class Test extends Application { public Test() { System.out.println("Test constructor is invoked."); } @Override // Override the start method in the Application class public void start(Stage primaryStage) { System.out.println("start method is invoked."); } public static void main(String[] args) { System.out.println("launch application."); Application.launch(args); } } A. launch application. start method is invoked. B. start method is invoked. Test constructor is invoked. C. Test constructor is invoked. start method is invoked. D. launch application. start method is invoked. Test constructor is invoked. E. launch application. Test constructor is invoked. start method is invoked.

E. launch application. Test constructor is invoked. start method is invoked.

14.27 To add a node to the the first row and second column in a GridPane pane, use ________. A. pane.getChildren().add(node, 1, 2); B. pane.add(node, 1, 2); C. pane.getChildren().add(node, 0, 1); D. pane.add(node, 0, 1); E. pane.add(node, 1, 0);

E. pane.add(node, 1, 0);

To add a node to the the first row and second column in a GridPane pane, use ________. A. pane.getChildren().add(node, 1, 2); B. pane.add(node, 1, 2); C. pane.getChildren().add(node, 0, 1); D. pane.add(node, 0, 1); E. pane.add(node, 1, 0);

E. pane.add(node, 1, 0);

To wrap a line in a text area ta, invoke ____________. A. ta.setLineWrap(false) B. ta.setLineWrap(true) C. ta.WrapLine() D. ta.wrapText() E. ta.setWrapText(true)

E. ta.setWrapText(true)

Consider the following code snippet: PrintWriter out = new PrintWriter("output.txt"); If a file named "output.txt" already exists, which of the following statements about the PrintWriter object is correct?

Existing data will be deleted before data are added to the file.

All methods in an abstract class must also be declared abstract. True/False

False

If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method. True/False

False

If two methods in the same class have the same name but different signatures, the second overrides the first. True/False

False

Which of the following is the correct syntax for creating a File object?

File inFile = new File("input.txt");

Consider the following code snippet: Scanner in = new Scanner(. . .); in.useDelimiter("[A-Za-z]+"); What characters will be read in using this code?

Only non-alphabetic characters will be read in.

Select an expression to complete the program segment below, which displays an error message and terminates normally if the String variable accountNumber does not contain an integer value. try { int number = Integer.parseInt(accountNumber); } catch ( ________________________ ) { System.out.println("Account number is not an integer value"); }

NumberFormatException exception

Select an expression to complete the program segment below, which displays an error message and terminates normally if the String variable accoutNumber does not contain an integer value

NumberFormatException exception

Which of the following statements about the try/finally statement is NOT true?

The finally clause is executed after the exception is propagated to its handler.

Consider the following code snippet: PrintWriter outputFile = new PrintWriter(filename); writeData(outputFile); outputFile.close(); How can the program ensure that the file will be closed if an exception occurs on the writeData call?

The program should declare the PrintWriter variable in a try-with-resources statement to ensure that the file is closed.

Consider the following code snippet: PrintWriter outputFile = new PrintWriter(filename); writeData(outputFile); outputFile.close(); How can the program ensure that the file will be closed if an exception occurs on the writeData call?

The program should declare the PrintWriter variable in a try-with-resources statement to ensure that the file is closed.

Consider the following code snippet, assuming in is an instantiated Scanner: if (in.hasNext()) { throw new IOException("End of file expected"); } Which of the following statements about this code is correct?

The program will throw an exception if there is data left in the input when the if statement is executed.

If the current method in a program will not be able to handle an exception, what should be coded into the method?

The throws clause should list the names of all exceptions that the method will not handle.

Consider the following code snippet: throw new IllegalArgumentException("This operation is not allowed!"); Which of the following statements about this code is correct?

This code constructs an object of type IllegalArgumentException and throws the object.

Consider the following code snippet. Scanner inputFile = new Scanner("dataIn.txt"); Which of the following statements is correct?

This code will not open a file named "dataIn.txt", but will treat the string "dataIn.txt" as an input value.

When reading words with a Scanner object, a word is defined as ____.

any sequence of characters that is not white space.

When you start a Java program from a command line and supply argument values, the values ____.

are stored as String values

Insert the missing code in the following code fragment. This fragment is intended to write an output file named dataOut.txt that resides in a folder named reports on the C: drive of a Windows system. public static void main(String[] args) throws IOException { PrintWriter outputFile = _______; . . . }

new PrintWriter("c:\\reports\\dataOut.txt")

Select an expression to complete the following statement, which is designed to construct a "PrintWriter" object to write the program output to a file named "dataout.txt". PrintWriter theFile = _______________________;

new PrintWriter("dataout.txt")

Insert the missing code in the following code fragment. This fragment is intended to read a file named dataIn.txt and write to a file named dataOut.txt. public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); PrintWriter out = _____________; . . . }

new PrintWriter(outputFileName)

Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and write to an output file named dataOut.txt. public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = _________; PrintWriter outFile = new PrintWriter("dataOut.txt"); . . . }

new Scanner(inputFile)

Insert the missing code in the following code fragment. This fragment is intended to read a web page. public static void main(String[] args) throws IOException { String address = "http://horstmann.com/index.html"; URL pageLocation = new URL(address); Scanner in = _________; . . . }

new Scanner(pageLocation.openStream())

Scanner in = new Scanner(. . .); String result = ""; int number = 0; if (in.hasNextInt()) { number = in.nextInt(); } result = in.next(); If the input file begins with the characters 626.14 average, what values will number and result have after this code is executed?

number will contain the value 0 and result will contain the value 626.14.

A JavaFX action event handler is an instance of _______. A. ActionEvent B. Action C. EventHandler D. EventHandler<ActionEvent>

D. EventHandler<ActionEvent>

A JavaFX event handler for event type T is an instance of _______. A. ActionEvent B. Action C. EventHandler D. EventHandler<T>

D. EventHandler<T>

Every class is either directly or indirectly derived from the Object class. True/False

True

Private members of the superclass cannot be accessed by the subclass. True/False

True

Look at the following code. Which line in ClassA has an error? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodA(double) {} Line 10 } A) 7 B) 8 C) 6 D) 9

B) 8

This annotation tells the Java compiler that a method is meant to override a method in the superclass. A) @Inherited B) @Override C) @Protected D) @Overload

B) @Override

What is required for an interface method that has a body? A) The method header must begin with the key word default. B) The @Default annotation must precede the method header. C) All of these D) A class that implements the interface must override the method.

A) The method header must begin with the key word default.

In an inheritance relationship: A) The superclass constructor always executes before the subclass constructor B) The constructor with the lowest overhead always executes first regardless of inheritance C) The subclass constructor always executes before the superclass constructor D) The unified constructor always executes first regardless of inheritance

A) The superclass constructor always executes before the subclass constructor

When an "is a" relationship exists between objects, it means that the specialized object has: A) all the characteristics of the general object, plus additional characteristics B) none of the characteristics of the general object C) some of the characteristics of the general class, but not all, plus additional characteristics D) some of the characteristics of the general object, but not all

A) all the characteristics of the general object, plus additional characteristics

An anonymous inner class must: A) either implement an interface or extend another class B) implement an interface C) both implement an interface and extend another class D) extend another class

A) either implement an interface or extend another class

A subclass can directly access: A) only public and protected members of the superclass B) only public and private members of the superclass C) only protected and private members of the superclass D) all members of the superclass

A) only public and protected members of the superclass

What key word can you use to call a superclass constructor explicitly? A) super B) extends C) this D) goto

A) super

Fill in the code below in the underline: public class Test { public static void main(String[] args) { Test test = new Test(); test.setAction(______________________________); } public void setAction(T1 t) { t.m(); } } interface T1 { public void m(); } A. () -> System.out.print("Action 1! ") B. (e) -> System.out.print("Action 1! ") C. System.out.print("Action 1! ") D. (e) -> {System.out.print("Action 1! ")}

A. () -> System.out.print("Action 1! ")

Which of the following statements are true? A. A Button can fire an ActionEvent. B. A Button can fire a MouseEvent. C. A Button can fire a KeyEvent. D. A TextField can fire an ActionEvent.

A. A Button can fire an ActionEvent. B. A Button can fire a MouseEvent. C. A Button can fire a KeyEvent. D. A TextField can fire an ActionEvent.

14.6 Which of the following statements are true? A. A Node can be placed in a Pane. B. A Node can be placed in a Scene. C. A Pane can be placed in a Control. D. A Shape can be placed in a Control.

A. A Node can be placed in a Pane.

Which of the following statements are true? A. A Node can fire an ActionEvent. B. A Noden can fire a MouseEvent. C. A Node can fire a KeyEvent. D. A Scene can fire a MouseEvent.

A. A Node can fire an ActionEvent. B. A Noden can fire a MouseEvent. C. A Node can fire a KeyEvent. D. A Scene can fire a MouseEvent.

14.3 Which of the following statements are true? A. A primary stage is automatically created when a JavaFX main class is launched. B. You can have multiple stages displayed in a JavaFX program. C. A stage is displayed by invoking the show() method on the stage. D. A scene is placed in the stage using the addScene method E. A scene is placed in the stage using the setScene method

A. A primary stage is automatically created when a JavaFX main class is launched. B. You can have multiple stages displayed in a JavaFX program. C. A stage is displayed by invoking the show() method on the stage. E. A scene is placed in the stage using the setScene method

Which of the following are the classes in JavaFX for representing an event? A. ActionEvent B. MouseEvent C. KeyEvent D. WindowEvent

A. ActionEvent B. MouseEvent C. KeyEvent D. WindowEvent

Which of the following statements are true? A. An anonymous inner class is an inner class without a name. B. An anonymous inner class must always extend a superclass or implement an interface, but it cannot have an explicit extends or implements clause. C. An anonymous inner class must implement all the abstract methods in the superclass or in the interface. D. An anonymous inner class always uses the no-arg constructor from its superclass to create an instance. If an anonymous inner class implements an interface, the constructor is Object(). E. An anonymous inner class is compiled into a class named OuterClassName$n.class.

A. An anonymous inner class is an inner class without a name. B. An anonymous inner class must always extend a superclass or implement an interface, but it cannot have an explicit extends or implements clause. C. An anonymous inner class must implement all the abstract methods in the superclass or in the interface. D. An anonymous inner class always uses the no-arg constructor from its superclass to create an instance. If an anonymous inner class implements an interface, the constructor is Object(). E. An anonymous inner class is compiled into a class named OuterClassName$n.class.

Which of the following statements are true? A. Inner classes can make programs simple and concise. B. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class. C. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class. D. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class.

A. Inner classes can make programs simple and concise. B. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class. C. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class. D. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class.

14.1 Why is JavaFX preferred? A. JavaFX is much simpler to learn and use for new Java programmers. B. JavaFX provides a multi-touch support for touch-enabled devices such as tablets and smart phones. C. JavaFX has a built-in 3D, animation support, video and audio playback, and runs as a standalone application or from a browser. D. JavaFX incorporates modern GUI technologies to enable you to develop rich Internet applications.

A. JavaFX is much simpler to learn and use for new Java programmers. B. JavaFX provides a multi-touch support for touch-enabled devices such as tablets and smart phones. C. JavaFX has a built-in 3D, animation support, video and audio playback, and runs as a standalone application or from a browser. D. JavaFX incorporates modern GUI technologies to enable you to develop rich Internet applications.

Suppose the following program displays a pane in the stage. What is the output if the user presses the key for letter B? import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; // import javafx classes omitted public class Test1 extends Application { @Override public void start(Stage primaryStage) { // Code to create and display pane omitted Pane pane = new Pane(); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage pane.requestFocus(); pane.setOnKeyPressed(e -> System.out.print("Key pressed " + e.getCode() + " ")); pane.setOnKeyTyped(e -> System.out.println("Key typed " + e.getCode())); } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. Key pressed B Key typed UNDEFINED B. Key pressed B Key typed C. Key typed UNDEFINED D. Key pressed B

A. Key pressed B Key typed UNDEFINED

__________ is a subclass of Animation. A. PathTransition B. FadeTransition C. Timeline D. Duration

A. PathTransition B. FadeTransition C. Timeline

Analyze the following code. import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); Button btCancel = new Button("Cancel"); EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }; btOK.setOnAction(handler); btCancel.setOnAction(handler); HBox pane = new HBox(5); pane.getChildren().addAll(btOK, btCancel); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. When clicking the OK button, the program displays The OK button is clicked. B. When clicking the Cancel button, the program displays The OK button is clicked. C. When clicking either button, the program displays The OK button is clicked twice. D. The program has a runtime error, because the handler is registered with more than one source.

A. When clicking the OK button, the program displays The OK button is clicked. B. When clicking the Cancel button, the program displays The OK button is clicked.

The properties _________ are defined in the Animation class. A. autoReverse B. cycleCount C. rate D. status

A. autoReverse B. cycleCount C. rate D. status

Which of the following code correctly registers a handler with a button btOK? A. btOK.setOnAction(e -> System.out.println("Handle the event")); B. btOK.setOnAction((e) -> System.out.println("Handle the event");); C. btOK.setOnAction((ActionEvent e) -> System.out.println("Handle the event")); D. btOK.setOnAction(e -> {System.out.println("Handle the event");});

A. btOK.setOnAction(e -> System.out.println("Handle the event")); B. btOK.setOnAction((e) -> System.out.println("Handle the event");); C. btOK.setOnAction((ActionEvent e) -> System.out.println("Handle the event")); D. btOK.setOnAction(e -> {System.out.println("Handle the event");});

To properties _________ are defined in the FadeTransition class. A. duration B. node C. fromValue D. toValue E. byValue

A. duration B. node C. fromValue D. toValue E. byValue

The properties _________ are defined in the PathTransition class. A. duration B. node C. orientation D. path

A. duration B. node C. orientation D. path

14.7 Which of the following statements are correct? A. new Scene(new Button("OK")); B. new Scene(new Circle()); C. new Scene(new ImageView()); D. new Scene(new Pane());

A. new Scene(new Button("OK")); D. new Scene(new Pane());

To handle the mouse click event on a pane p, register the handler with p using ______. A. p.setOnMouseClicked(handler); B. p.setOnMouseDragged(handler); C. p.setOnMouseReleased(handler); D. p.setOnMousePressed(handler);

A. p.setOnMouseClicked(handler);

When a subclass overloads a superclass method: A) Only the subclass method may be called with a subclass object B) Both methods may be called with a subclass object C) Neither method may be called with a subclass object D) Only the superclass method may be called with a subclass object

B) Both methods may be called with a subclass object

In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.print("This is the last statement " + "in the constructor."); } A) It will call the method super and pass the value 40 to it as an argument. B) It will call the constructor of ClassA that receives an integer as an argument. C) The method super will have to be defined before we can say what will happen. D) This cannot be determined from the code.

B) It will call the constructor of ClassA that receives an integer as an argument.

If a subclass constructor does not explicitly call a superclass constructor: A) the superclass fields will be set to the default values for their data types B) Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes C) Java will automatically call the superclass's default or no-arg constructor immediately after the code in the subclass's constructor executes D) it must include the code necessary to initialize the superclass fields

B) Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

Look at the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB() {} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC() {} Line 14 public void method1() {} Line 15 } Which method1 will be executed as a result of the following statements? ClassA item1 = new ClassC(); item1.method1(); A) Line 9 B) Line 14 C) Line 4 D) This is an error and will cause the program to crash.

B) Line 14

Replacing inadequate superclass methods with more suitable subclass methods is known as what? A) Method upgrading B) Method overriding C) Method overloading D) Tactical inheritance

B) Method overriding

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { super (40); System.out.println("This is the last statement " + "in the constructor."); } } A) No values may be passed to super. B) Nothing is wrong with the code. C) The method super is not defined. D) No values may be passed to super.

B) Nothing is wrong with the code.

Which of the following is TRUE about protected access? A) Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package. B) Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package. C) Protected members cannot be accessed by methods in any other classes. D) Protected members are actually named constants.

B) Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package.

If ClassC extends ClassB, which extends ClassA, this would be an example of: A) packaging B) a chain of inheritance C) multiple inheritance D) a family tree

B) a chain of inheritance

All fields declared in an interface: A) have protected access B) are final and static C) have private access D) must be initialized in the class implementing the interface

B) are final and static

The super statement that calls the superclass constructor: A) can appear in any method of the subclass B) must be the first statement in the subclass's constructor C) must be the first statement in the superclass's constructor D) is deprecated and is no longer supported in newer versions of Java

B) must be the first statement in the subclass's constructor

If a class contains an abstract method: A) All of these. B) the method will have only a header, but not a body, and end with a semicolon C) the method cannot be overridden in subclasses D) you must create an instance of the class

B) the method will have only a header, but not a body, and end with a semicolon

If a superclass does not have a default constructor or a no-arg constructor: A) then a class that inherits from it, does not inherit the data member fields from the superclass. B) then a class that inherits from it, must call one of the constructors that the superclass does have. C) then a class that inherits from it, must initialize the superclass values. D) then a class that inherits from it, must contain the default constructor for the superclass.

B) then a class that inherits from it, must call one of the constructors that the superclass does have.

Fill in the code below in the underline: public class Test { public static void main(String[] args) { Test test = new Test(); test.setAction2(______________________________); } public void setAction2(T2 t) { t.m(4.5); } } interface T2 { public void m(Double d); } A. () -> System.out.print(e) B. (e) -> System.out.print(e) C. e -> System.out.print(e) D. (e) -> {System.out.print(e);}

B. (e) -> System.out.print(e) C. e -> System.out.print(e) D. (e) -> {System.out.print(e);}

Fill in the code below in the underline: public class Test { public static void main(String[] args) { Test test = new Test(); System.out.println(test.setAction3(_____________)); } public double setAction3(T3 t) { return t.m(5.5); } } interface T3 { public double m(Double d); } A. () -> e * 2 B. (e) -> e * 2 C. e -> e * 2 D. (e) -> {e * 2;}

B. (e) -> e * 2 C. e -> e * 2

Given the following code which of the following is TRUE? public class ClassB implements ClassA{} A) ClassA must override each method in ClassB. B) ClassA inherits from ClassB. C) ClassB must override each method in ClassA. D) ClassB inherits from ClassA.

C) ClassB must override each method in ClassA.

Fill in the code to display the key pressed in the text. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.text.Text; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Pane pane = new Pane(); Text text = new Text(20, 20, "Welcome"); pane.getChildren().add(text); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage text.setFocusTraversable(true); text.setOnKeyPressed(_______________________); } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. () -> text.setText(e.getText()) B. (e) -> text.setText(e.getText()) C. e -> text.setText(e.getText()) D. e -> {text.setText(e.getText());}

B. (e) -> text.setText(e.getText()) C. e -> text.setText(e.getText()) D. e -> {text.setText(e.getText());}

Which of the following statements are true? A. A Shape can fire an ActionEvent. B. A Shape can fire a MouseEvent. C. A Shape can fire a KeyEvent. D. A Text is a Shape. E. A Circle is a Shape.

B. A Shape can fire a MouseEvent. C. A Shape can fire a KeyEvent. D. A Text is a Shape. E. A Circle is a Shape.

14.5 Which of the following statements are true? A. A Scene is a Node. B. A Shape is a Node. C. A Stage is a Node. D. A Control is a Node. E. A Pane is a Node.

B. A Shape is a Node. D. A Control is a Node. E. A Pane is a Node.

Which of the following statements are true? A. A handler object fires an event. B. A source object fires an event. C. Any object such a String object can fire an event. D. A handler is registered with the source object for processing the event.

B. A source object fires an event. D. A handler is registered with the source object for processing the event.

Suppose A is an inner class in Test. A is compiled into a file named _________. A. A.class B. Test$A.class C. A$Test.class D. Test&A.class

B. Test$A.class

Analyze the following code: import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleDoubleProperty; public class Test { public static void main(String[] args) { DoubleProperty balance = new SimpleDoubleProperty(); balance.addListener(ov -> System.out.println(2 + balance.doubleValue())); balance.set(4.5); } } A. The program displays 4.5. B. The program displays 6.5. C. The program would display 4.5 if the balance.set(4.5) is placed before the balance.addLisnter(...) statement. D. The program would display 6.5 if the balance.set(4.5) is placed before the balance.addLisnter(...) statement.

B. The program displays 6.5.

Analyze the following code: public class Test { public static void main(String[] args) { Test test = new Test(); test.setAction(() -> System.out.print("Action 1! ")); } public void setAction(T t) { t.m1(); } } interface T { public void m1(); public void m2(); } A. The program displays Action 1. B. The program has a compile error because T is not a functional interface. T contains multiple methods. C. The program would work if you delete the method m2 from the interface T. D. The program has a runtime error because T is not a functional interface. T contains multiple methods.

B. The program has a compile error because T is not a functional interface. T contains multiple methods. C. The program would work if you delete the method m2 from the interface T.

14.2 Every JavaFX main class __________. A. implements javafx.application.Application B. extends javafx.application.Application C. overrides start(Stage s) method D. overrides start() method

B. extends javafx.application.Application C. overrides start(Stage s) method

To register a source for an action event with a handler, use __________. A. source.addAction(handler) B. source.setOnAction(handler) C. source.addOnAction(handler) D. source.setActionHandler(handler)

B. source.setOnAction(handler)

Look at the following code. What is missing from ClassA? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodB(double) {} Line 10 } A) It does not overload methoda. B) Nothing is missing. It is a complete class. C) It does not override methoda. D) It does not have a constructor.

C) It does not override methoda.

Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10); } } A) This cannot be determined form the code shown. B) The method super will have to be defined before we can say what will happen. C) It will call the constructor of ClassA that receives an integer as an argument. D) It will call the method named super and pass the value 10 to it as an argument.

C) It will call the constructor of ClassA that receives an integer as an argument.

This is a variable whose value is never changed, but it isn't declared with the final key word. A) anonymous inner variable B) virtually constant variable C) effectively final variable D) default variable

C) effectively final variable

If two methods have the same name but different signatures, they are: A) overridden B) subclass methods C) overloaded D) superclass methods

C) overloaded

A subclass may call an overridden superclass method by: A) using the extends keyword before the method is called B) prefixing its name with the name of the superclass in parentheses C) prefixing its name with the super key word and a dot (.) D) calling the superclass method first and then calling the subclass method

C) prefixing its name with the super key word and a dot (.)

In an interface all methods have: A) protected access B) packaged access C) public access D) private access

C) public access

Analyze the following code. import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); btOK.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. The program has a compile error because no handlers are registered with btOK. B. The program has a runtime error because no handlers are registered with btOK. C. The message "The OK button is clicked" is displayed when you click the OK button. D. The handle method is not executed when you click the OK button, because no handler is registered with btOK.

C. The message "The OK button is clicked" is displayed when you click the OK button.

Analyze the following code. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a button and place it in the scene Button btOK = new Button("OK"); btOK.setOnAction(e -> System.out.println("OK 1")); btOK.setOnAction(e -> System.out.println("OK 2")); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. When clicking the button, the program displays OK1 OK2. B. When clicking the button, the program displays OK1. C. When clicking the button, the program displays OK2. D. The program has a compile error, because the setOnAction method is invoked twice.

C. When clicking the button, the program displays OK2.

To create a KeyFrame with duration 1 second, use ______________. A. new KeyFrame(1000, handler) B. new KeyFrame(1, handler) C. new KeyFrame(Duration.millis(1000), handler) D. new KeyFrame(Duration.seconds(1), handler)

C. new KeyFrame(Duration.millis(1000), handler) D. new KeyFrame(Duration.seconds(1), handler)

14.8 To add a circle object into a pane, use _________. A. pane.add(circle); B. pane.addAll(circle); C. pane.getChildren().add(circle); D. pane.getChildren().addAll(circle);

C. pane.getChildren().add(circle); D. pane.getChildren().addAll(circle);

Fill in the code in the underlined location to display the mouse point location when the mouse is pressed in the pane. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Pane pane = new Pane(); ______________________________________ Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("Test"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. pane.setOnMouseClicked((e) -> System.out.println(e.getX() + ", " + e.getY())); B. pane.setOnMouseReleased(e -> {System.out.println(e.getX() + ", " + e.getY())}); C. pane.setOnMousePressed(e -> System.out.println(e.getX() + ", " + e.getY())); D. pane.setOnMouseDragged((e) -> System.out.println(e.getX() + ", " + e.getY()));

C. pane.setOnMousePressed(e -> System.out.println(e.getX() + ", " + e.getY()));

A JavaFX action event handler contains a method ________. A. public void actionPerformed(ActionEvent e) B. public void actionPerformed(Event e) C. public void handle(ActionEvent e) D. public void handle(Event e)

C. public void handle(ActionEvent e)

Look at the following code. Which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a) {} Line 5 public final int method2 (double b) {} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB() {} Line 10 public int method1 (int b) {} Line 11 public int method2 (double c) {} Line 12 } A) 5 B) 10 C) 4 D) 11

D) 11

Look at the following code. Which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double) {} Line 5 A) 1 B) 3 C) 2 D) 4

D) 4

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC A) ClassA B) ClassC C) Cannot tell D) ClassB

D) ClassB

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super (40); } } A) No values may be passed to super. B) Nothing is wrong with the code. C) The method super is not defined. D) The call to the method super must be the first statement in the constructor.

D) The call to the method super must be the first statement in the constructor.

Look at the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB() {} Line 9 public void method1() {} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC() {} Line 14 public void method1() {} Line 15 } Which method will be executed when the following statements are executed? ClassC item1 = new ClassA(); item1.method1(); A) Line 4 B) Line 9 C) Line 14 D) This is an error and will cause the program to crash.

D) This is an error and will cause the program to crash.

In UML diagrams, inheritance is shown: A) With a line that has a closed arrowhead at one end that points to the superclass B) With a line that has an open arrowhead at one end that points to the subclass C) With a line that has a closed arrowhead at one end that points to the subclass D) With a line that has an open arrowhead at one end that points to the superclass

D) With a line that has an open arrowhead at one end that points to the superclass

Like a family tree, a ________ shows the inheritance relationship between classes. A) flowchart B) class map C) binary tree D) class hierarchy

D) class hierarchy

When one object is a specialized version of another object, there is this type of relationship between them. A) direct B) has a C) contains a D) is a

D) is a

If ClassA extends ClassB, then: A) neither public or private members in ClassB can be directly accessed in ClassA B) private members in ClassB are changed to protected members in ClassA C) public and private members of ClassB are public and private, respectively, in ClassA D) public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

D) public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

Supose the follwoing program displays a pane in the stage. What is the output if the user presses the DOWN arrow key? import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; // import javafx classes omitted public class Test1 extends Application { @Override public void start(Stage primaryStage) { // Code to create and display pane omitted Pane pane = new Pane(); Scene scene = new Scene(pane, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage pane.requestFocus(); pane.setOnKeyPressed(e -> System.out.print("Key pressed " + e.getCode() + " ")); pane.setOnKeyTyped(e -> System.out.println("Key typed " + e.getCode())); } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } A. Key pressed DOWN Key typed UNDEFINED B. Key pressed DOWN Key typed C. Key typed UNDEFINED D. Key pressed DOWN

D. Key pressed DOWN

Suppose A is an anonymous inner class in Test. A is compiled into a file named _________. A. A.class B. Test$A.class C. A$Test.class D. Test$1.class E. Test&1.class

D. Test$1.class

To handle the key pressed event on a pane p, register the handler with p using ______. A. p.setOnKeyClicked(handler); B. p.setOnKeyTyped(handler); C. p.setOnKeyReleased(handler); D. p.setOnKeyPressed(handler);

D. p.setOnKeyPressed(handler);

Which of the following methods is not defined in the Animation class? A. pause() B. play() C. stop() D. resume()

D. resume()

Which statement is true about a non-static inner class? A. It must implement an interface. B. It is accessible from any other class. C. It can only be instantiated in the enclosing class. D. It must be final if it is declared in a method scope. E. It can access private instance variables in the enclosing object.

E. It can access private instance variables in the enclosing object.

14.4 What is the output of the following JavaFX program? import javafx.application.Application; import javafx.stage.Stage; public class Test extends Application { public Test() { System.out.println("Test constructor is invoked."); } @Override // Override the start method in the Application class public void start(Stage primaryStage) { System.out.println("start method is invoked."); } public static void main(String[] args) { System.out.println("launch application."); Application.launch(args); } } A. launch application. start method is invoked. B. start method is invoked. Test constructor is invoked. C. Test constructor is invoked. start method is invoked. D. launch application. start method is invoked. Test constructor is invoked. E. launch application. Test constructor is invoked. start method is invoked.

E. launch application. Test constructor is invoked. start method is invoked.

In an inheritance relationship, the subclass constructor always executes before the superclass constructor. True/False

False

Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class. True/False

False

A functional interface is simply an interface that has one abstract method. True/False

True

An abstract class is not instantiated, but serves as a superclass for other classes. True/False

True


Related study sets

Makroökonómia alapfogalmai és a nemzetgazdaság

View Set

Cumulative Accounting True False

View Set