OOP Final Exam Multiple Choice/TF

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

D

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

C

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

False

A compilation error will occur if the file doesn't exist when creating a FileInputStream for the file. T/F

True

A subclass cannot extend more than one class, but may implement any number of interfaces. T/F

False

A subclass of a non-abstract class must be non-abstract. T/F

True

All methods in an interface are abstract. T/F

True

All the numeric wrapper classes implement the Comparable interface. T/F

True

An abstract class can be extended. T/F

True

An interface can extend any number of interfaces using the extends keyword. T/F

False

An interface can extend any number of interfaces using the implements keyword. T/F

False

An interface cannot extend more than one interface. T/F

D

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. The program has a compile error, because the setOnAction method is invoked twice. C. When clicking the button, the program displays OK1. D. When clicking the button, the program displays OK2.

B

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. Only bt1 displays the icon and bt2 does not display the icon. B. Two buttons displayed with the same icon. C. Only bt2 displays the icon and bt1 does not display the icon. D. Two buttons displayed with different icons.

B

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 would display 6.5 if the balance.set(4.5) is placed before the balance.addLisnter(...) statement. B. The program displays 6.5. C. The program displays 4.5. D. The program would display 4.5 if the balance.set(4.5) is placed before the balance.addLisnter(...) statement.

AB

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

False

At least one method in an abstract class must be abstract. T/F

True

Closing an OutputStream ensures that the data in the buffer are sent to the destination. T/F

BD

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

A

If you output ten int values to file using DataOutputStream, what will be the size of the file? A. 40 bytes B. 80 bytes C. 10 bytes

True

InputStream and OutputStream are abstract classes. T/F

ABCD

Invoking new File(String filename) may throw ___________. A. Throwable B. Exception C. IOException D. FileNotFoundExcetpion

True

RandomAccessFile, DataInputStream, and DataOutputStream share the same file formats. T/F

A

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

B

Suppose Integer x = new Integer(3); x holds ____. A. value 3 B. a reference value to an Integer object C. an integer value

C

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 typed UNDEFINED B. Key pressed B Key typed C. Key pressed B Key typed UNDEFINED D. Key pressed B

False

The FileFoundException occurs when creating FileOutputStream for a nonexistent file. T/F

True

The FileNotFoundException occurs when creating FileInputStream for a nonexistent file. T/F

True

The FileWriter, FileReader, FileInputStream, FileOutputStream, and RandomAccessFile classes can be used to process external files. T/F

False

The Number class is an instance of Comparable. T/F

ABCE

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

ABCDE

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

True

The class PrintStream is used in JDK 1.02, but is deprecated in JDK1.1. T/F

D

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

True

The name of abstract class and interface is in italic in the UML. T/F

True

The numeric wrapper classes are subclasses of Number. T/F

ABCD

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

ABCDE

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

True

The read method, the write method, and creating stream constructors can throw IOException errors. T/F

BC

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

D

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

True

To determine whether a file exists, you can use the exists() method on a File object. T/F

B

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

B

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

B

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

C

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

E

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.

ABCD

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

ABCDE

Which of the following statements are true about abstract classes. A. A subclass can be abstract even if its superclass is concrete. B. It is possible to declare an abstract class that contains no abstract methods. C. If a subclass of an abstract superclass does not implement all the abstract methods, the subclass must be declared abstract. D. An abstract method cannot be contained in a non-abstract class. E. An abstract class cannot be instantiated using the new operator.

ABCD

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

ACDE

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

BE

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

ABCD

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

ABCDE

Which of the following statements correctly creates a Font object?

True

You can create an Integer object from an integer by using the Integer constructor with the int argument. T/F

ABCDE

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

True

You cannot create an instance of an abstract class using the new operator. T/F

ABCD

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

B

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 message "The OK button is clicked" is displayed when you click the OK button. C. The handle method is not executed when you click the OK button, because no handler is registered with btOK. D. The program has a runtime error because no handlers are registered with btOK.


Ensembles d'études connexes

Prepu: Chapter 15: Nursing Care of the Child with an Infection

View Set

Chapter 11 Practice Quiz Answer Key - Making Sense of Data

View Set

Combo with Barrons 3500: A and 24 others

View Set

Chapter 14 (Law on Cooperatives)

View Set

Emergency preparedness response Course (clinician course) Pre-Test

View Set

communications cassella Chapters 1-5

View Set

13. Legacy of Ancient Indian History: Important Observations

View Set