Final Exam Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

To prevent a class from being instantiated, ________. A) don't use any modifiers on the constructor B) use the private modifier on the constructor C) use the static modifier on the constructor D) use the public modifier on the constructor

B) use the private modifier on the constructor

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

D) Inheritance

A child class is allowed to define a method with the same name and parameter list as a method in the parent class. True False

True

A data structure includes support operations for accessing and manipulating the data. True False

True

A data structure is a collection of data organized in some fashion. True False

True

Files must be closed before terminating the program to ensure that data is not lost True False

True

In Java, a subclass can only extend one parent class. True False

True

Private members of a parent class are inherited by child classes True False

True

Regression testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine

Trye

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 titleprimaryStage.setScene(scene); // Place the scene in the stageprimaryStage.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);}}

Two buttons displayed with the same icon.

A map can access any element by using the key can access any elements by using the index can access element only at the front can access only the element with the highest priority

can access any element by using the key

A list can access any elements by using the index can access element only at the front can access any element by using the key can access only the element with the highest priority

can access any elements by using the index

A queue can access any elements by using the index can access element only at the front can access only the element with the highest priority can access any element by using the key

can access element only at the front

A priority queue can access element only at the front can access any elements by using the index can access any element by using the key can access only the element with the highest priority

can access only the element with the highest priority

What is the String returned after executing the following statement "Welcome".subString(3); a) "Wel" b) "lcome" c) "Welcome" d) "come"

d) "come"

Given the following code, what is the output after executing line 7 a) String str1 has length of 15 b) String str1 has length of 14 c) String str1 has length of 17 d) String str1 has length of 18

d) String str1 has length of 18

What's the git command that downloads your repository from GitHub to your computer? a) push b) fork c) commit d) clone

d) clone

What is the correct statement to complete the comparator shown below. a) return v1 - v2 b) return v2.getPts() - v1.getPts(); c) return v1 + v2 d) return v1.getPts() - v2.getPts();

d) return v1.getPts() - v2.getPts();

What is the String returned after executing the following statement "We#lc#om#e".split("o"); a) returns an array with the following elements: "We" , "lc" , "om" , "e" b) returns "Welcome" c) returns an array with the following elements: "W" , "e" , "l" , "c" , "o" , "m" , "e" d) returns an array with the following elements: "We#lc#" , "m#e"

d) returns an array with the following elements: "We#lc#" , "m#e"

Examine the following code. What is true about the variables within the class? they can be accessed by any class outside the assignment package they can be accessed by other classes in the assignment package they can be accessed by child classes of Batter that are outside the assignment package they cannot be accessed outside the class Batter

they cannot be accessed outside the class Batter

Match the java access specifier to the correct definition ---- can be accessed anywhere ---- cannot be accessed outside the package ---- cannot be accessed outside the class ---- only subclasses can access outside of the package 1. Private 2. Default (void) 3. Public 4. Protected

--3- can be accessed anywhere --2- cannot be accessed outside the package --1- cannot be accessed outside the class --4- only subclasses can access outside of the package

Which of the following statements are true? (Select all that apply)

-Constructors do not have a return type, not even void. -Constructors are invoked using the new operator when an object is created. -Constructors must have the same name as the class itself. -Multiple constructors can be defined in a class.

Which of the following statements are correct?

-new Scene(new Button("OK")); -new Scene(new Pane());

What is the first index of an array?

0

Match the term to the correct definition: ____ store data as numbers ____ store data as characters binary files, text files

1. Binary files 2. Text files

Match the statement to the term. ___returns a formatted string with the value in var formatted to an integer. —-returns a formatted string with the value in var formatted to 2 decimal places.

1. String.format("%d", var); 2. String.format("%2.2f", var);

Match the java keyword to the correct definition: _____ used to create new objects _____ used to invoke parent class method _____ used to indicate that a class is derived from another class new , super, extends

1. new 2. super 3. extends

Which index of the array holds the value of 5? int [] numbers = new int[10]; for(int i=0; i<10; i++) numbers[i] = 2 * i + 1;

2

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

B) resume()

Given the declaration Circle x = new Circle(), which of the following statement is most accurate? A) x contains a reference to a Circle object. B) x contains an object of the Circle type. C) You can assign an int value to x. D) x contains an int value.

A) x contains a reference to a Circle object.

Assume double[][] x = new double[4][5], what are x.length and x[2].length

4 and 5

Suppose an ArrayList list contains {"red", "green", "red", "green"}. What is the list after the following code? list.remove("red"); A) {"green", "red", "green"} B) {"red", "green", "green"} C) {"red", "green", "red", "green"} D) {"green", "green"}

A) {"green", "red", "green"}

Inheritance means ________. A) that a variable of supertype can refer to a subtype object B) that a class can extend another class C) that data fields should be declared private D) that a class can contain another class

B) that a class can extend another class

What is the message displayed when this code is executed?

5 success

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________. A) 2.0 B) 5.5 C) 3.5 D) 3.4 E) undefined

A) 2.0

How many elements are in array double[] list = new double[5]? A) 5 B) 4 C) 0 D) 6

A) 5

Which of the following statements are true? A) Multiple constructors can be defined in a class. B) Constructors must have the same name as the class itself. C) Constructors do not have a return type, not even void. D) Constructors are invoked using the new operator when an object is created.

A) Multiple constructors can be defined in a class. B) Constructors must have the same name as the class itself. C) Constructors do not have a return type, not even void. D) Constructors are invoked using the new operator when an object is created.

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

Which of the following statements are true? A) The default constructor is a no-arg constructor. B) At least one constructor must always be defined explicitly. C) Every class has a default constructor. D) A default constructor is provided automatically if no constructors are explicitly declared in the class.

A) The default constructor is a no-arg constructor. D) A default constructor is provided automatically if no constructors are explicitly declared in the class.

Analyze the following code: public class Test { public static void main(String[] args) { A a = new A(); a.print(); } } class A { String s; A(String s) { this.s = s; } void print() { System.out.println(s); } } A) The program would compile and run if you change A a = new A() to A a = new A("5"). B) The program has a compilation error because the print method is not a public method. C) The program has a compilation error because class A is not a public class. D) The program compiles and runs fine and prints nothing.

A) The program would compile and run if you change A a = new A() to A a = new A("5").

Which of the following statements are true? A) To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass. B) Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them. C) A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. D) A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden. E) It is a compilation error if two methods differ only in return type in the same class.

A) To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass. B) Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them. C) A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. D) A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden. E) It is a compilation error if two methods differ only in return type in the same class.

To determine whether a file exists, you can use the exists() method on a File object. A) True B) False

A) True

What is the representation of the third element in an array called a? A) a[2] B) a(2) C) a(3) D) a[3]

A) a[2]

An object is an instance of a _________. A) class B) program C) data D) method

A) class

What is the output of the following JavaFX program? A) launch application. Test constructor is invoked. start method is invoked. B) launch application. start method is invoked. Test constructor is invoked. C) launch application. start method is invoked. D) Test constructor is invoked. start method is invoked. E) start method is invoked. Test constructor is invoked.

A) launch application. Test constructor is invoked. start method is invoked.

You can create an ArrayList using ________. A) new ArrayList<>() B) new ArrayList[100] C) new ArrayList[]

A) new ArrayList<>()

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

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

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

A) overrides start(Stage s) method

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, 0, 1); pane.add(node2, 1, 1); C) pane.add(node1, node2, 0); D) pane.addRow(1, node1, node2); E) pane.addRow(0, node1, node2);

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

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

A) public abstract void method();

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

A) public void handle(ActionEvent e)

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

A) rb.isSelected().

Polymorphism means ________. A) that a variable of supertype can refer to a subtype object B) that a class can extend another class C) that a class can contain another class D) that data fields should be declared private

A) that a variable of supertype can refer to a subtype object

Encapsulation means ________. A) that data fields should be declared private B) that a class can contain another class C) that a class can extend another class D) that a variable of supertype can refer to a subtype object

A) that data fields should be declared private

A instance of a subclass is also an instance of its superclass. A) true B) false

A) true

A method can throw a subclass of RuntimeException. A) true B) false

A) true

A method can throw a subclass of RuntimeException. Question options: A) true B) false

A) true

Closing a PrintWriter object ensures that the data in the buffer are sent to the file. A) true B) false

A) true

Closing an OutputStream ensures that the data in the buffer are sent to the destination. A) true B) false

A) true

Every object is an instance of the Object class. A) true B) false

A) true

The FileWriter, FileReader, FileInputStream, FileOutputStream, and RandomAccessFile classes can be used to process external files. A) true B) false

A) true

The order of methods in a class is immaterial. A) true B) false

A) true

You can access a class variable using a syntax like objectName.classVariable or ClassName.classVariable. A) true B) false

A) true

You can always successfully cast a subclass to a superclass. A) true B) false

A) true

You use the plus sign (+) to denote public data or methods. A) true B) false

A) true

You use underline to denote static variables and methods. A) true B) false

A) true

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

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

Which statement is the correct declaration and initialization of an ArrayList of String values? ArrayList<String> name; name = new ArrayList<String>(); ArrayList name; name = new ArrayList<String>(); ArrayList<String> name; name = ArrayList<String>(); String<ArrayList> name; name = new String<ArrayList>

ArrayList<String> name; name = new ArrayList<String>();

What is the value of times displayed? public class Test { public static void main(String[] args) { Count myCount = new Count(); int times = 0; for (int i=0; i<100; i++) increment(myCount, times); System.out.println( "myCount.count = " + myCount.count); System.out.println("times = "+ times); } public static void increment(Count c, int times) { c.count++;times++; } } class Count { int count; Count(int c) { count = c; } Count() { count = 1; } } A) 100 B) 0 C) 101 D) 99 E) 98

B) 0

How many elements are in array matrix (int[][] matrix = new int[5][5])? A) 30 B) 25 C) 20 D) 14

B) 25

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

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

________ represents an entity in the real world that can be distinctly identified. A) A method B) An object C) A class D) A data field

B) An object

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

B) EventHandler<ActionEvent>

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

Which class do you use to write data into a text file? A) File B) PrintWriter C) Scanner D) System

B) PrintWriter

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

B) new Label(text);

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

B) overrides start(Stage s) method

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

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

Analyze the following code. // Program 1: public class Test { public static void main(String[] args) { Object circle1 = new Circle(); Circle circle2 = new Circle(); System.out.println(circle1.equals(circle2)); } } class Circle { double radius; public boolean equals(Circle circle) { return this.radius == circle.radius; } } // Program 2: public class Test { public static void main(String[] args) { Circle circle1 = new Circle(); Circle circle2 = new Circle(); System.out.println(circle1.equals(circle2)); } } class Circle { double radius; public boolean equals(Object circle) { return this.radius ==((Circle)circle).radius; } } A) Program 1 displays true and Program 2 displays true B) Program 1 displays false and Program 2 displays true C) Program 1 displays true and Program 2 displays false D) Program 1 displays false and Program 2 displays false

B) Program 1 displays false and Program 2 displays true

What is displayed on the console when running the following program? 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) You cannot catch RuntimeException errors. B) The program displays Welcome to Java two times followed by End of the block two times. C) The program displays Welcome to Java three times followed by End of the block. D) The program displays Welcome to Java two times followed by End of the block.

B) The program displays Welcome to Java two times followed by End of the block two times.

Analyze the following code: A) The program displays two radio buttons. The two radio buttons are grouped. B) The program displays two radio buttons. The two radio buttons are not grouped. C) The program displays one radio button with text Java. D) The program displays one radio button with text C++.

B) The program displays two radio buttons. The two radio buttons are not grouped.

Analyze the following code: public class Test { public static void main(String[] args) { A a = new A(); a.print(); } } class A { String s; A(String s) { this.s = s; } void print() { System.out.println(s); } } A) The program would compile and run if you change A a = new A() to A a = new A("5"). B) The program has a compilation error because class A does not have a default constructor. C) The program has a compilation error because class A is not a public class. D) The program compiles and runs fine and prints nothing.

B) The program has a compilation error because class A does not have a default constructor.

Analyze the following code: A) The program runs fine and displays one circle. B) The program has a compile error since the circle is added to a pane twice. C) The program has a runtime error since the circle is added to a pane twice. D) The program runs fine and displays two circles.

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

A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this? A) The variable should be marked private and an accessor method provided. B) The variable should be marked protected. C) The variable should be marked public. D) The variable should be marked private. E) The variable should have no special access modifier

B) The variable should be marked protected.

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

B) abstract class A { abstract void unfinished(); }

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

B) circle.setFill(Color.BLACK);

The keyword ________ is required to declare a class. A) public B) class C) private D) All of the above.

B) class

A final class can be extended. A) true B) false

B) false

You can create an instance of the Math class. A) true B) false

B) false

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Java"); String s2 = new String("Java"); System.out.print((s1 == s2) + " " + (s1.equals(s2))); } } A) true true B) false true C) true false D) false false

B) false true

The default value for data field of a boolean type, numeric type, object type is ________, respectively. A) false, 1, null B) false, 0, null C) true, 1, null D) true, 0, null E) true, 1, Null

B) false, 0, null

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

B) interface A { void print();}

If an exception occurs in a try-catch block, the code in the finally clause ________. A) may be executed B) is always executed C) is not executed D) is not executed if the exception is caught

B) is always executed

If an exception occurs in a try-catch block, the code in the finally clause ________. A) may be executed B) is executed C) is not executed D) is not executed if the exception is caught

B) is executed

What is the output of the following JavaFX program? A) start method is invoked. Test constructor is invoked. B) launch application. Test constructor is invoked. start method is invoked. C) launch application. start method is invoked. D) launch application. start method is invoked. Test constructor is invoked. E) Test constructor is invoked. start method is invoked.

B) launch application. Test constructor is invoked. start method is invoked.

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

B) lbl.setTextFill(Color.RED);

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) lbl.setTextFill(Color.RED);

The UML uses ________ before a member name to indicate that the member is protected. A) + B) - C) # D) ?

C) #

Assume int[] t = {1, 2, 3, 4}. What is t.length? A) 0 B) 3 C) 4 D) 5

C) 4

________ is invoked to create an object. A) A method with a return type B) A method with the void return type C) A constructor D) The main method

C) A constructor

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

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

Analyze the following code. public class Test { public static void main(String[] args) { int n = 2; xMethod(n); System.out.println("n is " + n); } void xMethod(int n) { n++; } } A) The code prints n is 2. B) The code prints n is 1. C) The code has a compile error because xMethod is not declared static. D) The code prints n is 3. E) The code has a compile error because xMethod does not return a value.

C) The code has a compile error because xMethod is not declared static.

Suppose you enter 34.3 57.8 789, then press the ENTER key. Analyze the following code. Scanner input = new Scanner(System.in); double v1 = input.nextDouble(); double v2 = input.nextDouble(); String line = input.nextLine(); A) After the last statement is executed, line contains characters '7', '8', '9'. B) After the last statement is executed, line contains characters ' ', '7', '8', '9', '\n'. C) After the last statement is executed, line contains characters '7', '8', '9', '\n'. D) After the last statement is executed, line contains characters ' ', '7', '8', '9'

D) After the last statement is executed, line contains characters ' ', '7', '8', '9'.

What is displayed on the console when running the following program? 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 two times followed by End of the block. B) You cannot catch RuntimeException errors. C) The program displays Welcome to Java two times followed by End of the block two times. D) The program displays Welcome to Java three times followed by End of the block.

C) The program displays Welcome to Java two times followed by End of the block two times.

Review the following code and select its outcome abstract class A {} class B extends A {} class C extends A {} public class ExQuesA { public static void main(String[] args) { C var1 = new B(); if(var1 instanceof c) { } else { B var 3 = (B)var1; } } } A) Program compiles and executes without any errors B) Syntax error as A cannot be a variable C) Type Mismatch syntax error and the program would not compile D) Program compiles but execution throws a ClassCastException since B and C are siblings

C) Type Mismatch syntax error and the program would not compile

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) b is an instance of A. B) b is an instance of C. C) b is an instance of A followed by b is an instance of C. D) Nothing

C) b is an instance of A followed by b is an instance of C.

Given the following code: class C1 {} class C2 extends C1 { } class C3 extends C2 { } class C4 extends C1 {} C1 c1 = new C1(); C2 c2 = new C2(); C3 c3 = new C3(); C4 c4 = new C4(); Which of the following expressions evaluates to false? A) c3 instanceof C1 B) c1 instanceof C1 C) c4 instanceof C2 D) c2 instanceof C1

C) c4 instanceof C2

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

C) checked exceptions

Every JavaFX main class ________. A) overrides start() metho B) implements javafx.application.Application C) extends javafx.application.Application D) overrides launch() method

C) extends javafx.application.Application

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

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

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

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

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

C) resume()

Inheritance means ________. A) that a variable of supertype can refer to a subtype object B) that data fields should be declared private C) that a class can extend another class D) that a class can contain another class

C) that a class can extend another class

Analyze the following code: class Test { private double i; public Test(double i) { this.t(); this.i = i; } public Test() { System.out.println("Default constructor"); this(1); } public void t() { System.out.println("Invoking t"); } } A) this.t() may be replaced by t(). B) this.i may be replaced by i. C) this(1) must be called before System.out.println("Default constructor"). D) this(1) must be replaced by this(1.0).

C) this(1) must be called before System.out.println("Default constructor").

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing]? A) x.remove(2) B) x.remove(0) C) x.remove("Singapore")

C) x.remove("Singapore")

Which method do you use to remove an element from a set or list named x? A) x.delete(element) B) x.removes(element) C) x.remove(element) D) x.deletes(element) E) None of these

C) x.remove(element)

A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this? A) The variable should be marked private and an accessor method provided. B) The variable should be marked private C) The variable should be marked protected D) The variable should have no special access modifier E) The variable should be marked public

C) The variable should be marked protected

Given the following code, what is the output after executing line 8.

Charater at index position 3 of String str1 is F

________ is NOT a subclass of Animation. A) Timeline B) PathTransition C) FadeTransition D) Duration

D) Duration

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

D) Inheritance

Suppose list is a LinkedList that contains 1 million int values. Analyze the following code: A: for (int i = 0; i < list.size(); i++) sum += list.get(i); B:for (int i: list) sum += i;

Code fragment B runs faster than code fragment A.

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________. A) 0 B) 1 C) 2 D) 3 E) 4

D) 3

_______ is a construct that defines objects of the same type. A) A method B) A data field C) An object D) A class

D) A class

Analyze the following code: 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".

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

D) Inheritance

What is the output of the following code? public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends Person { private String getInfo() { return "Student"; } } class Person { private String getInfo() { return "Person"; } public void printPerson() {System.out.println(getInfo()); } } A) Student Student B) Student Person C) Person Student D) Person Person

D) Person Person

Analyze the following code: A) The program displays one radio button with text C++. B) The program displays two radio buttons. The two radio buttons are grouped. C) The program displays one radio button with text Java. D) The program displays two radio buttons. The two radio buttons are not grouped.

D) The program displays two radio buttons. The two radio buttons are not grouped.

What is wrong in the following code? class TempClass { int i; public void TempClass(int j) { int i = j; } } public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); } } A) The program has a compilation error because TempClass does not have a default constructor. B) The program compiles fine, but it does not run because class C is not public. C) The program compiles and runs fine. D) The program has a compilation error because TempClass does not have a constructor with an int argument.

D) The program has a compilation error because TempClass does not have a constructor with an int argument.

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) calendar.get(Calendar.WEEK_OF_YEAR)

Analyze the following code: A) The addAll method needs to be replaced by the add method. B) The image object cannot be shared by two ImageViews. C) The program runs fine and displays two images. D) 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").

D) 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").

Which method can be used to read a whole line from the file? A) nextDouble B) next C) nextInt D) nextLine

D) nextLine

To create an InputStream to read from a file on a Web server, you use the method ________ in the URL class. A) getInputStream(); B) obtainInputStream(); C) connectStream(); D) openStream();

D) openStream();

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

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

Which of the following methods override the equals method in the Object class? A) public static boolean equals(Object o) B) public void equals(Object o) C) public boolean equals(SomeType o) D) public boolean equals(Object o)

D) public boolean equals(Object o)

Which of the following methods override the equals method in the Object class? A) public void equals(Object o) B) public boolean equals(SomeType o) C) public static boolean equals(Object o) D) public boolean equals(Object o)

D) public boolean equals(Object o)

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing, Chicago, Singapore]? A) x.add(0, "Chicago") B) x.add("Chicago") C) x.add(2, "Chicago") D) x.add(1, "Chicago")

D) x.add(1, "Chicago")

Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code? A) {"red", "red", "green"} B) {"green"} C) {} D) {"red", "green"}

D) {"red", "green"}

Assume int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}, what are x[0].length, x[1].length, and x[2].length? A) 3, 3, and 4 B) 2, 2, and 2 C) 3, 3, and 3 D) 2, 3, and 3 E) 2, 3, and 4

E) 2, 3, and 4

Suppose A is an anonymous inner class in Test. A is compiled into a file named ________. Question options: A) A$Test.class B) Test$A.class C) Test&1.class D) A.class E) Test$1.class

E) Test$1.class

Analyze the following code. public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = null;System.out.println(test.x); } } A) The program has a compile error because x has not been initialized. B) The program has a compile error because Test does not have a default constructor. C) The program has a compile error because test is not initialized. D) The program has a compile error because you cannot create an object from the class that defines the object. E) The program has a runtime NullPointerException because test is null while executing test.x.

E) The program has a runtime NullPointerException because test is null while executing test.x.

A abstract class must contain abstract methods

False

A finally clause is always required in a try-catch block. True False

False

A set in Java can contain duplicate elements True False

False

In Java, a subclass can only implement one interface. True False

False

The Java Collections Framework supports these collections Maps Lists Graphs Sets

Maps Lists Sets

Match the term to its definition. ____ models has-a relationships and represents an ownership relationship between two objects where the child cannot exist independent of the parent ____ is a general binary relationship that describes an activity between two classes ____ models has-a relationships and represents an ownership relationship between two objects where the child can exist independently of the parent 1. Association 2. Aggregation 3. Composition

Match the term to its definition. __3__ models has-a relationships and represents an ownership relationship between two objects where the child cannot exist independent of the parent __1__ is a general binary relationship that describes an activity between two classes __2__ models has-a relationships and represents an ownership relationship between two objects where the child can exist independently of the parent

Which one of the following best describes a feature provided by Junit? Provides support for documenting source code Code compilation Provides support to test drivers for running tests Provides support for refactoring code

Provides support to test drivers for running tests

What is the result of executing the following code package eXAM2; public class QuesA { public static void main(String[] args) { try { System.out.println("Step 1"); String [] names = {"Bugs", "Daffy", "Porky"}; System.out.println(names[3]); System.out.println("Step 2"); int i = 2/3; System.out.println("Step 3"); }catch(ArithmeticException e0) {System.out.println("Oooh nooo");

Step 1 Not again! Finally done

Suppose A is an inner class in Test. A is compiled into a file named ______

Test$A.class

Given the following code, what is the output after executing line 11.

Text in String str2 is MY FINAL EXAM 2021

Suppose that the Person class does not have an equals method. What happens when an expression x==y; is evaluated for two Person objects? Runtime error The expression is true if x and y refer to objects with the same Person name The expression is true if x and y refer to the exact same object Compile error

The expression is true if x and y refer to the exact same object

Match the term to the correct definition. ____ complete pathname to a file starting at the root directory ____ does not specify any top-level folder, so the path is relative to the current directory 1. relative path 2. absolute path

_2___ complete pathname to a file starting at the root directory _1___ does not specify any top-level folder, so the path is relative to the current directory

Match the statement to the correct term. ____ For strings that are going to remain constant throughout the program ____ For strings that will be changed with lots of logic and operations in the construction of the string 1. String 2. StringBuilder

__1__ For strings that are going to remain constant throughout the program __2__ For strings that will be changed with lots of logic and operations in the construction of the string

Match the definitions to the terms. ___ has a contiguous memory location ____ holds the constant number of values of the same type ____ cannot store primitive type ____ can be multi dimensional ____ automatically grows and shrinks as needed ____ can only be single dimensional 1. Array 2. ArrayList

__1__ has a contiguous memory location __1__ holds the constant number of values of the same type __2__ cannot store primitive type __1__ can be multi dimensional __2__ automatically grows and shrinks as needed __2__ can only be single dimensional

Match the statement to the term ____ returns a formatted string with the value in var formatted to an integer. ____ returns a formatted string with the value in var formatted to 5 decimal places. 1. String.format("%d", var); 2. String.format("%2.5f", var);

__1__ returns a formatted string with the value in var formatted to an integer. __2__ returns a formatted string with the value in var formatted to 5 decimal places.

Match the statement to the term. ____Program execution is a series of "procedures" operating on data ____Program execution is a series of object interactions ____Procedures (or "operations") and data are separate constructs. ____Data and operations on those data belong together as a single unit 1.Procedural Programming 2.Object-oriented Programming

__1__ Program execution is a series of "procedures" operating on data __2__ Program execution is a series of object interactions __1__ Procedures (or "operations") and data are separate constructs. __2__Data and operations on those data belong together as a single unit

Match the term to the definition. ____ examine the program that is accessible from the outside and observe it externally visible outcome. ___ examine the source code to figure out what to test and how best to test the code. 1. Whitebox testing 2. Blackbox testing

__2__ examine the program that is accessible from the outside and observe it externally visible outcome. __1__ examine the source code to figure out what to test and how best to test the code.

Match the java keyword to the correct definition ____ test whether the object is an instance of the specified class or implements an interface ___ is not associated with any specific instance but belongs to the class instead ___ reference to the current object 1. this 2. static 3. instanceof

__3_ test whether the object is an instance of the specified class or implements an interface __2_ is not associated with any specific instance but belongs to the class instead __1_ reference to the current object

Match the term to the definition. __3__ occurs whenever the external behavior of a system does not conform to that prescribed in the system specification. __2__ an incorrect state of the system that could cause the system to fail. __1__ a piece of code that cause an incorrect state. 1. Fault 2. Error 3. Failure

__3__ occurs whenever the external behavior of a system does not conform to that prescribed in the system specification. __2__ an incorrect state of the system that could cause the system to fail. __1__ a piece of code that cause an incorrect state.

Match the term to its definition. ____ Ability to take the form of itself, parent, grandparent, etc ___ wrapping up of data and operations on the data under a single unit ___ acquiring all the properties and behaviors of a parent object ___showing only essential information 1. Abstraction 2. Encapsulation 3. Inheritance 4. Polymorphism

__4__ Ability to take the form of itself, parent, grandparent, etc __2__ wrapping up of data and operations on the data under a single unit __3__ acquiring all the properties and behaviors of a parent object __1__showing only essential information

A unit is object-oriented programming is usually considered as an interface a class a package a system

a class

What is the regular expression that matches all characters between the range A to Z? a) [A-Z] b) . c) * d) [0-9] e) ^ f) {7,10} g) $ h) [a-z]

a) [A-Z]

Java String is an object that represents some ordered sequence of char values a) True b) False

a) True

What is the String returned after executing the following statement "Welcome".subString(2); a) "come" b) "lcome" c) "Welcome" d) "Wel"

b) "lcome"

A stack is a container that allows elements to be stored and removed a) in a first-in-first-out fashion b) in a last-in-first-out fashion c) according to priority d) last-in-last-out fashion

b) in a last-in-first-out fashion

What is the String returned after executing the following statement "We#lc#om#e".split("#"); a) returns an array with the following elements: "W" , "e" , "l" , "c" , "o" , "m" , "e" b) returns an array with the following elements: "We" , "lc" , "om" , "e" c) returns "Welcome" d) returns an array with the following elements: "We#lc#" , "m#e"

b) returns an array with the following elements: "We" , "lc" , "om" , "e"

What is the correct way to check if two string (s1 and s2) are the same? a) s1 == s2 b) s1.equals(s2) c) s1 = s2 d) s1.same(s2)

b) s1.equals(s2)

What is the String returned after executing the following statement "Welcome".subString(2,3); a) "lc" b) "Welcome" c) "l" d) "Wel"

c) "l"

What is Git? a) A remote repository platform b) A programming language c) A version control system d) A slang

c) A version control system

What's the git command that uploads your code from your computer to GitHub? a) clone b) commit c) push d) stage

c) push

What is the special character that matches a character at the end of a string? a) {7,10} b) [0-9] c) * d) ^ e) [a-z] f) . g) $ h) [A-Z]

g) $

Which of the following data types does not implement the Collection interface?

map

What is the message displayed when this code is executed?

master 450

Which statement can be used to create an input object (read from file) or text file temp.txt? new File("temp.txt") new Scanner("temp.txt") new BufferedReader(new FileReader("temp.txt")) new String("temp.txt")

new BufferedReader(new FileReader("temp.txt"))

Given the following string: String stData = "Bugs; Bunny; Daffy; Duck" ; What is the most appropriate delimiter to use with Scanner to get tokens with the words and no spaces or semicolon?

new Scanner(stData).useDelimiter("\\s;\\s");

Which statement below is the correct way to retrieve the first element in the nums ArrayList? nums[1] nums[0] nums(0 nums.get(0)

nums.get(0)

To add a node to the the first row and second column in a GridPane pane, use

pane.add(node, 1, 0);

To add a node into a pane, use _______

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

What's the git command that allows you to add files for future commit to GitHub? a) clone b) stage c) commit d) push

push

What is the correct code for the equals method of the Citizen class if name and ssn muct match. return (((Citizen)c).name==this.name && ((Citizen)c).ssn==this.ssn); return (((Citizen)c).name.equals(this.name) || ((Citizen)c).ssn==this.ssn); return (c.name==this.name && c.ssn==this.ssn); return (((Citizen)c).name.equals(this.name) && ((Citizen)c).ssn==this.ssn);

return (((Citizen)c).name.equals(this.name) && ((Citizen)c).ssn==this.ssn);

What is the correct code for the equals method of the Student class if name and eid must match. return (s.name==this.name && s.eid==this.eid); return (s.name==this.name || s.eid==this.eid); return (((Student)s).name.equals(this.name) || ((Student)s).eid==this.eid); return (((Student)s).name.equals(this.name) && ((Student)s).eid==this.eid);

return (((Student)s).name.equals(this.name) && ((Student)s).eid==this.eid);

To register a source for an action event with a handler, use

source.setOnAction(handler)

The method ________ gets the contents of the text field tf.

tf.getText()

Invoking ________ returns the number of the elements in an ArrayList x.

x.size()

What is the regular expression that matches a 7 to 10 sequence of characters?

{7,10}


Kaugnay na mga set ng pag-aaral

AP US Government Unit 3: Civil Liberties and Civil Rights Essential Knowledge (Redesign)

View Set

IEM 3403: Project Management Ch. 1 & 2

View Set

BIO 102 - EXAM 4: CHAPTER 14-기출문제

View Set

HA: Chapter 15- Assessing Head and Neck

View Set

Bio102 Unit 4 Mastering Biology Quizzes

View Set

Marketing for Entrepreneurs Exam 1

View Set