CS II Chapter 14 Quiz, CS II Chapter 13 Quiz, CS II Chapter 12 Quiz, CS II Chapter 11 Quiz, CS II Chapter 19 Quiz, 18

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

An instance of _________ describes programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors.. A. RuntimeException B. Exception C. Error D. Throwable E. NumberFormatException

A

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

Analyze the following code: public class Test { public static void main(String[] args) throws MyException { System.out.println("Welcome to Java"); } } class MyException extends Error { } A. You should not declare a class that extends Error, because Error raises a fatal error that terminates the program. B. You cannot declare an exception in the main method. C. You declared an exception in the main method, but you did not throw it. D. The program has a compile error

A

Analyze the following program. public class Test { public static void main(String[] args) { try { String s = "5.6"; Integer.parseInt(s); // Cause a NumberFormatException int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (Exception ex) { System.out.println(ex); } } } A. An exception is raised due to Integer.parseInt(s); B. An exception is raised due to 2 / i; C. The program has a compile error. D. The program compiles and runs without exceptions

A

Assume Calendar calendar = new GregorianCalendar(). __________ returns the month of the year. A. calendar.get(Calendar.MONTH) B. calendar.get(Calendar.MONTH_OF_YEAR) C. calendar.get(Calendar.WEEK_OF_MONTH) D. calendar.get(Calendar.WEEK_OF_YEAR)

A

What exception type does the following program throw? public class Test { public static void main(String[] args) { System.out.println(1 / 0); } } A. ArithmeticException B. ArrayIndexOutOfBoundsException C. StringIndexOutOfBoundsException D. ClassCastException E. No exception

A

What is displayed on the console when running the following program? public class Test { public static void main(String[] args) { try { method(); System.out.println("After the method call"); } catch (NumberFormatException ex) { System.out.println("NumberFormatException"); } catch (RuntimeException ex) { System.out.println("RuntimeException"); } } static void method() { String s = "5.6"; Integer.parseInt(s); // Cause a NumberFormatException int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } } A. The program displays NumberFormatException. B. The program displays NumberFormatException followed by After the method call. C. The program displays NumberFormatException followed by RuntimeException. D. The program has a compile error. E. The program displays RuntimeException

A

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

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

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

Which of the following statements is incorrect? A. Integer i = 4.5; B. Double i = 4.5; C. Object i = 4.5; D. Number i = 4.5;

A

Which of the following statements regarding abstract methods is false? A. An abstract class can have instances created using the constructor of the abstract class. B. An abstract class can be extended. C. A subclass of a non-abstract superclass can be abstract. D. A subclass can override a concrete method in a superclass to declare it abstract. E. An abstract class can be used as a data type

A

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

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

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

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

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

Which of the following statements are true? A. A class should describe a single entity and all the class operations should logically fit together to support a coherent purpose. B. A class should always contain a no-arg constructor. C. The constructors must always be public. D. The constructors may be protected

A and D

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

A, B and C

The GeometricObject and Circle classes are defined in this chapter. Analyze the following code. Which statements are correct? public class Test { public static void main(String[] args) { GeometricObject x = new Circle(3); GeometricObject y = (Circle)(x.clone()); System.out.println(x); System.out.println(y); } } A. The program has a compile error because the clone() method is protected in the Object class. B. After you override the clone() method and make it public in the Circle class, the problem can compile and run just fine, but y is null if Circle does not implement the Cloneable interface. C. To enable a Circle object to be cloned, the Circle class has to override the clone() method and implement the java.lang.Cloneable interface. D. If GeometricObject implements Cloneable and Circle overrides the clone() method, the clone() method will work fine to clone Circle objects

A, B, C and D

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

A, B, C and D

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

A, B, C and D

Which of the following is poor design? A. A data field is derived from other data fields in the same class. B. A method must be invoked after/before invoking another method in the same class. C. A method is an instance method, but it does not reference any instance data fields or invoke instance methods. D. A parameter is passed from a constructor to initialize a static data field

A, B, C and D

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, B, C and D

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, B, C and D

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, B, C and D

Which of the following statements are true? A. The String class implements Comparable. B. The Date class implements Comparable. C. The Double class implements Comparable. D. The BigInteger class implements Comparable

A, B, C and D

Which of the following statements are true? A. You use the keyword throws to declare exceptions in the method heading. B. A method may declare to throw multiple exceptions. C. To throw an exception, use the key word throw. D. If a checked exception occurs in a method, it must be either caught or declared to be thrown from the method

A, B, C and D

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, B, C and D

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, B, C and D

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, B, C and E

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

A, B, C, D and E

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

A, B, C, D and E

Which of the following statements are true? A. Inheritance models the is-a relationship between two classes. B. A strong is-a relationship describes a direct inheritance relationship between two classes. C. A weak is-a relationship describes that a class has certain properties. D. A strong is-a relationship can be represented using class inheritance. E. A weak is-a relationship can be represented using interfaces

A, B, C, D and E

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, B, C, D and E

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, B, and C

An instance of _________ are unchecked exceptions. A. RuntimeException B. Exception C. Error D. Throwable E. NumberFormatException

A, C and E

A method must declare to throw ________. A. unchecked exceptions B. checked exceptions C. Error D. RuntimeException

B

An instance of _________ describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program. A. RuntimeException B. Exception C. Error D. Throwable E. NumberFormatException

B

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

The java.util.Calendar and java.util.GregorianCalendar classes are introduced in Chapter 11. Analyze the following code. Which of the following statements is correct? 1. import java.util.*; 2. public class Test { 3. public static void main(String[] args) { 4. Calendar[] calendars = new Calendar[10]; 5. calendars[0] = new Calendar(); 6. calendars[1] = new GregorianCalendar(); 7. } 8. } A. The program has a compile error on Line 4 because java.util.Calendar is an abstract class. B. The program has a compile error on Line 5 because java.util.Calendar is an abstract class. C. The program has a compile error on Line 6 because Calendar[1] is not of a GregorianCalendar type. D. The program has no compile errors

B

What exception type does the following program throw? public class Test { public static void main(String[] args) { int[] list = new int[5]; System.out.println(list[5]); } } A. ArithmeticException B. ArrayIndexOutOfBoundsException C. StringIndexOutOfBoundsException D. ClassCastException E. No exception

B

What is displayed on the console when running the following program? public class Test { public static void main (String[] args) { try { System.out.println("Welcome to Java"); return; } finally { System.out.println("The finally clause is executed"); } } } A. Welcome to Java B. Welcome to Java followed by The finally clause is executed in the next line C. The finally clause is executed D. None of the above

B

What is displayed on the console when running the following program? public class Test { public static void main (String[] args) { try { System.out.println("Welcome to Java"); } finally { System.out.println("The finally clause is executed"); } } } A. Welcome to Java B. Welcome to Java followed by The finally clause is executed in the next line C. The finally clause is executed D. None of the above

B

What is displayed on the console when running the following program? public class Test { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to HTML"); } finally { System.out.println("The finally clause is executed"); } } } A. Welcome to Java, then an error message. B. Welcome to Java followed by The finally clause is executed in the next line, then an error message. C. The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is executed, then an error message. D. None of the above.

B

What is displayed on the console when running the following program? public class Test { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2/i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } A. The program displays Welcome to Java three times followed by End of the block. B. The program displays Welcome to Java two times followed by End of the block. C. The program displays Welcome to Java three times. D. The program displays Welcome to Java two times

B

What is wrong in the following program? public class Test { public static void main (String[] args) { try { System.out.println("Welcome to Java"); } } } A. You cannot have a try block without a catch block. B. You cannot have a try block without a catch block or a finally block. C. A method call that does not declare exceptions cannot be placed inside a try block. D. Nothing is wrong

B

Which of the following declares an abstract method in an abstract Java class? A. public abstract method(); B. public abstract void method(); C. public void abstract method(); D. public void method() {} E. public abstract void method() {}

B

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

Analyze the following code: public class Test1 { public Object max(Object o1, Object o2) { if ((Comparable)o1.compareTo(o2) >= 0) { return o1; } else { return o2; } } } A. The program has a compile error because Test1 does not have a main method. B. The program has a compile error because o1 is an Object instance and it does not have the compareTo method. C. The program has a compile error because you cannot cast an Object instance o1 into Comparable. D. The program would compile if ((Comparable)o1.compareTo(o2) >= 0) is replaced by (((Comparable)o1).compareTo(o2) >= 0)

B and D

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

Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a no-arg constructor. Which of the following is correct? A. A a = new A(); B. A a = new B(); C. B b = new A(); D. B b = new B();

B and D

Suppose A is an interface, B is a concrete class with a no-arg constructor that implements A. Which of the following is correct? A. A a = new A(); B. A a = new B(); C. B b = new A(); D. B b = new B();

B and D

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, D and E

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, D and E

An instance of _________ describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully. A. RuntimeException B. Exception C. Error D. Throwable E. NumberFormatException

C

Analyze the following code. Which of the following statements is correct? public class Test { public static void main(String[] args) { Number x = new Integer(3); System.out.println(x.intValue()); System.out.println(x.compareTo(new Integer(4))); } } A. The program has a compile error because an Integer instance cannot be assigned to a Number variable. B. The program has a compile error because intValue is an abstract method in Number. C. The program has a compile error because x does not have the compareTo method. D. The program compiles and runs fine

C

The java.lang.Number and its subclasses are introduced in Chapter 11. Analyze the following code. Number numberRef = new Integer(0); Double doubleRef = (Double)numberRef; Which of the following statements is correct? A. There is no such class named Integer. You should use the class Int. B. The compiler detects that numberRef is not an instance of Double. C. A runtime class casting exception occurs, since numberRef is not an instance of Double. D. The program runs fine, since Integer is a subclass of Double. E. You can convert an int to double, so you can cast an Integer instance to a Double instance

C

The relationship between an interface and the class that implements it is A. Composition B. Aggregation C. Inheritance D. None

C

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

What exception type does the following program throw? public class Test { public static void main(String[] args) { String s = "abc"; System.out.println(s.charAt(3)); } } A. ArithmeticException B. ArrayIndexOutOfBoundsException C. StringIndexOutOfBoundsException D. ClassCastException E. No exception

C

What is displayed on the console when running the following program? public class Test { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; double y = 2.0 / i; System.out.println("Welcome to HTML"); } finally { System.out.println("The finally clause is executed"); } } } A. Welcome to Java. B. Welcome to Java followed by The finally clause is executed in the next line. C. The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is executed. D. None of the above.

C

What is displayed on the console when running the following program? public class Test { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2/i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } System.out.println("End of the block"); } } A. The program displays Welcome to Java three times followed by End of the block. B. The program displays Welcome to Java two times followed by End of the block. C. The program displays Welcome to Java two times followed by End of the block two times. D. You cannot catch RuntimeException errors

C

What is displayed on the console when running the following program? public class Test { public static void main(String[] args) { try { method(); System.out.println("After the method call"); } catch (RuntimeException ex) { System.out.println("RuntimeException"); } catch (Exception ex) { System.out.println("Exception"); } } static void method() throws Exception { try { String s = "5.6"; Integer.parseInt(s); // Cause a NumberFormatException int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("RuntimeException"); } catch (Exception ex) { System.out.println("Exception"); } } } A. The program displays RuntimeException twice. B. The program displays Exception twice. C. The program displays RuntimeException followed by After the method call. D. The program displays Exception followed by RuntimeException. E. The program has a compile error

C

What is the best suitable relationship between Employee and Faculty? A. Composition B. Aggregation C. Inheritance D. None

C

Which of the following class definitions defines a legal abstract class? A. class A { abstract void unfinished() { } } B. class A { abstract void unfinished(); } C. abstract class A { abstract void unfinished(); } D. public class abstract A { abstract void unfinished(); }

C

Which of the following statements is false? A. If you compile an interface without errors, a .class file is created for the interface. B. If you compile a class without errors but with warnings, a .class file is created. C. If you compile a class with errors, a .class file is created for the class. D. If you compile an interface without errors, but with warnings, a .class file is created for the interface

C

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

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

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

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

C and D

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

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

The Rational class in this chapter is defined as a subclass of java.lang.Number. Which of the following expressions is correct? A. Rational.doubleValue(); B. Rational.doubleValue("5/4"); C. new Rational(5, 4).doubleValue(); D. new Rational(5, 4).toDoubleValue(); E. new Rational(5, 4).intValue();

C and E

Which of the following are incorrect? A. An abstract class contains constructors. B. The constructors in an abstract class should be protected. C. The constructors in an abstract class are private. D. You may declare a final abstract class. E. An interface may contain constructors

C, D and E

A Java exception is an instance of __________. A. RuntimeException B. Exception C. Error D. Throwable E. NumberFormatException

D

Analyze the following code. Number[] numberArray = new Integer[2]; numberArray[0] = new Double(1.5); Which of the following statements is correct? A. You cannot use Number as a data type since it is an abstract class. B. Since each element of numberArray is of the Number type, you cannot assign an Integer object to it. C. Since each element of numberArray is of the Number type, you cannot assign a Double object to it. D. At runtime, new Integer[2] is assigned to numberArray. This makes each element of numberArray an Integer object. So you cannot assign a Double object to it

D

Analyze the following code. 1. public class Test { 2. public static void main(String[] args) { 3. Fruit[] fruits = {new Fruit(2), new Fruit(3), new Fruit(1)}; 4. java.util.Arrays.sort(fruits); 5. } 6. } class Fruit { private double weight; public Fruit(double weight) { this.weight = weight; } } A. The program has a compile error because the Fruit class does not have a no-arg constructor. B. The program has a runtime error on Line 3 because the Fruit class does not have a no-arg constructor. C. The program has a compile error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable. D. The program has a runtime error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable

D

Analyze the following code. public class Test { public static void main(String[] args) { java.util.Date x = new java.util.Date(); java.util.Date y = x.clone(); System.out.println(x = y); } } A. A java.util.Date object is not cloneable. B. x = y in System.out.println(x = y) causes a compile error because you cannot have an assignment statement inside a statement. C. x = y in System.out.println(x = y) causes a runtime error because you cannot have an assignment statement inside a statement. D. The program has a compile error because the return type of the clone() method is java.lang.Object

D

Analyze the following code. Which of the following statements is correct? public class Test { public static void main(String[] args) { Number x = new Integer(3); System.out.println(x.intValue()); System.out.println((Integer)x.compareTo(new Integer(4))); } } A. The program has a compile error because an Integer instance cannot be assigned to a Number variable. B. The program has a compile error because intValue is an abstract method in Number. C. The program has a compile error because x cannot be cast into Integer. D. The program has a compile error because the member access operator (.) is executed before the casting operator. E. The program compiles and runs fine

D

Analyze the following code: public class Test { public static void main(String[] args) { try { String s = "5.6"; Integer.parseInt(s); // Cause a NumberFormatException int i = 0; int y = 2 / i; } catch (Exception ex) { System.out.println("NumberFormatException"); } catch (RuntimeException ex) { System.out.println("RuntimeException"); } } } A. The program displays NumberFormatException. B. The program displays RuntimeException. C. The program displays NumberFormatException followed by RuntimeException. D. The program has a compile error

D

Assume Calendar calendar = new GregorianCalendar(). __________ returns the week of the year. A. calendar.get(Calendar.MONTH) B. calendar.get(Calendar.MONTH_OF_YEAR) C. calendar.get(Calendar.WEEK_OF_MONTH) D. calendar.get(Calendar.WEEK_OF_YEAR)

D

Assume an employee can work for only one company. What is the best suitable relationship between Company and Employee? A. None B. Aggregation C. Inheritance D. Composition

D

Show the output of running the class Test in the following code lines: interface A { } class C { } class B extends D implements A { } public class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); if (b instanceof C) System.out.println("b is an instance of C"); } } class D extends C { } A. Nothing. B. b is an instance of A. C. b is an instance of C. D. b is an instance of A followed by b is an instance of C

D

The Rational class in this chapter extends java.lang.Number and implements java.lang.Comparable. Analyze the following code. 1. public class Test { 2. public static void main(String[] args) { 3. Number[] numbers = {new Rational(1, 2), new Integer(4), new Double(5.6)}; 4. java.util.Arrays.sort(numbers); 5. } 6. } A. The program has a compile error because numbers is declared as Number[], so you cannot assign {new Rational(1, 2), new Integer(4), new Double(5.6)} to it. B. The program has a runtime error because numbers is declared as Number[], so you cannot assign {new Rational(1, 2), new Integer(4), new Double(5.6)} to it. C. The program has a compile error because numbers is declared as Number[], so you cannot pass it to Arrays.sort(Object[]). D. The program has a runtime error because the compareTo methods in Rational, Integer, and Double classes do not compare the value of one type with a value of another type

D

The output from the following code is __________. java.util.ArrayList<String> list = new java.util.ArrayList<String>(); list.add("New York"); java.util.ArrayList<String> list1 = (java.util.ArrayList<String>)(list.clone()); list.add("Atlanta"); list1.add("Dallas"); System.out.println(list1); A. [New York] B. [New York, Atlanta] C. [New York, Atlanta, Dallas] D. [New York, Dallas]

D

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

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

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

What exception type does the following program throw? public class Test { public static void main(String[] args) { Object o = new Object(); String d = (String)o; } } A. ArithmeticException B. ArrayIndexOutOfBoundsException C. StringIndexOutOfBoundsException D. ClassCastException E. No exception

D

What exception type does the following program throw? public class Test { public static void main(String[] args) { Object o = null; System.out.println(o); } } A. ArithmeticException B. ArrayIndexOutOfBoundsException C. StringIndexOutOfBoundsException D. No exception E. NullPointerException

D

Which of the following is a correct interface? A. interface A { void print() { }; } B. abstract interface A { print(); } C. abstract interface A { abstract void print() { };} D. interface A { void print();}

D

______ is not a reference type. A. A class type B. An interface type C. An array type D. A primitive type

D

Assume Calendar calendar = new GregorianCalendar(). __________ returns the number of days in a month. A. calendar.get(Calendar.MONTH) B. calendar.get(Calendar.MONTH_OF_YEAR) C. calendar.get(Calendar.WEEK_OF_MONTH) D. calendar.get(Calendar.WEEK_OF_YEAR) E. calendar.getActualMaximum(Calendar.DAY_OF_MONTH)

E

The following code causes Java to throw _________. int number = Integer.MAX_VALUE + 1; A. RuntimeException B. Exception C. Error D. Throwable E. no exceptions

E

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

What exception type does the following program throw? public class Test { public static void main(String[] args) { Object o = null; System.out.println(o.toString()); } } A. ArithmeticException B. ArrayIndexOutOfBoundsException C. StringIndexOutOfBoundsException D. ClassCastException E. NullPointerException

E

What is the output of running class Test? public class Test { public static void main(String[] args) { new Circle9(); } } public abstract class GeometricObject { protected GeometricObject() { System.out.print("A"); } protected GeometricObject(String color, boolean filled) { System.out.print("B"); } } public class Circle9 extends GeometricObject { /** No-arg constructor */ public Circle9() { this(1.0); System.out.print("C"); } /** Construct circle with a specified radius */ public Circle9(double radius) { this(radius, "white", false); System.out.print("D"); } /** Construct a circle with specified radius, filled, and color */ public Circle9(double radius, String color, boolean filled) { super(color, filled); System.out.print("E"); } } A. ABCD B. BACD C. CBAE D. AEDC E. BEDC

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

E

Which of the following statements regarding abstract methods is false? A. Abstract classes have constructors. B. A class that contains abstract methods must be abstract. C. It is possible to declare an abstract class that contains no abstract methods. D. An abstract method cannot be contained in a nonabstract class. E. A data field can be declared abstract

E


Set pelajaran terkait

Sampling Distribution and Estimation

View Set

Environmental science ch 8 true or false

View Set

Exam #4 Chapter 39: Management of Patients with Oral and Esophageal Disorders

View Set

ITN - Modules 1 - 3: Basic Network Connectivity and Communications

View Set

BSAN 160 - Activities and Quiz Questions

View Set