Midterm

Ace your homework & exams now with Quizwiz!

Radio buttons are normally used when you want the user to be able to select one or more options from a group of several possible options. A) True B) False

False

You can declare an enumerated data type inside a method. A) True B) False

False

To preserve an image's aspect ratio you can use the ImageView class's PreserveAspectRatio method. A) True B) False

False

In Java, you do not use the NEW operator when you use a(n) _______. A) two-dimensional array B) initialization list C) array size declarator D) any of these

Initialization list

An event handler class will not be executed unless it has been registered with the correct control. A) True B) False

True

Once an array is created, its size cannot be changed. A) True B) False

True

The java.lang package is automatically imported into all Java programs. A) True B) False

True

When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable. A) True B) False

True

If ClassC is derived from ClassB which is derived from ClassA, this would be an example of ________. A) linear inheritance B) multiple interfaces C) cascading classes D) a chain of inheritance

a chain of inheritance

A constructor ________. A) has the return type of void B) always accepts two arguments C) has the same name as the class D) always has a private access specifier

has the same name as the class

The ________ key word is used to call a superclass constructor explicitly. A) super B) this C) goto D) extends

super

When a reference variable is passed as an argument to a method ________. A) the method has access to the object that the variable references B) the method becomes a static method C) a copy of the variable's value is passed into the method's parameter D) the program terminates

the method has access to the object that the variable references

If a[] and b[] are two integer arrays, the expression a == b compares the array contents. A) True B) False

False

Without a base case, a recursive method will call itself only once and stop. A) True B) False

False

The JVM periodically performs the _______ process to remove unreferenced objects from memory. A) system restore B) garbage collection C) memory sweeping D) memory shuffling

Garbage collection

Given the following method header, what will be returned from the method? public Rectangle getRectangle( ) A) an object of the class Rectangle B) a graph of a rectangle C) the address of an object of the Rectangle class D) the values stored in the data members of the Rectangle object

the address of an object of the Rectangle class

A ________ member's access is somewhere between public and private. A) protected B) final C) package D) static

protected

In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass. A) a hierarchy chart B) a CRC card C) pseudocode D) a UML diagram

A UML diagram

A class becomes abstract when you place the ________ key word in the class definition. A) super B) final C) abstract D) extends

Abstract

The following statement is an example of ______. Import java.util.Scanner; A) a conditional IMPORT statement B) an explicit IMPORT statement C) an unconditional IMPORT statement D) a wildcard IMPORT statement

An explicit IMPORT statement

Which of the following will create a CheckBox that displays pizza and shows up as selected? A) CheckBox checkOne("pizza") = setSelected(true); B) CheckBox checkOne = new CheckBox("pizza");CheckBox.setSelected(false); C) CheckBox checkOne = new CheckBox("pizza");checkOne.setSelected(true); D) CheckBox checkOne.setSelected(true) = "pizza";

CheckBox checkOne = new CheckBox("pizza");checkOne.setSelected(true);

The key word this is the name of a reference variable that is available to all static methods. A) True B) False

False

The public access specifier for a field indicates that the field may not be accessed by statements outside the class. A) True B) False

False

The term "default constructor" is applied to the first constructor written by the author of the class. A) True B) False

False

A constructor ________. A) has the same name as the class B) Always accepts two arguments C) always has a private access specifier D) has the return type of VOID

Has the same name as the class

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

True

In a class hierarchy ________. A) the more general classes are toward the left of the tree and the more specialized classes are toward the right B) the more general classes are toward the right of the tree and the more specialized classes are toward the left C) the more general classes are toward the bottom of the tree and the more specialized classes are toward the top D) the more general classes are toward the top of the tree and the more specialized classes are toward the bottom

the more general classes are toward the top of the tree and the more specialized classes are toward the bottom

After the header, the body of the method appears inside a set of ________. A) double quotes, " " B) braces, { } C) brackets, [ ] D) parentheses, ( )

braces, { }

The ________ method removes an item from an ArrayList at a specific index. A) clear B) pop C) deleteAt D) remove

remove

You can use the ________ method to replace an item at a specific location in an ArrayList. A) replace B) add C) set D) remove

set

The scope of a public instance field is ________. A) inside the class but not inside any method B) only the class in which it is defined C) the instance methods and methods outside the class D) inside the parentheses of a method header

the instance methods and methods outside the class

Which of the following statements will create a reference, str, to the String "Hello, World"? A) string str = "Hello, World"; B) str = "Hello, World"; C) String str = new "Hello, World"; D) String str = "Hello, World";

String str = "Hello, World";

It is common practice in object-oriented programming to make all of a class's ________. A) fields public B) fields and methods public C) fields private D) methods private

fields private

Two or more methods in a class may have the same name as long as ________. A) they have different parameter lists B) You cannot have two methods with the same name. C) they have different return types D) they have different return types but the same parameter list

they have different parameter lists

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

@Override

The ________ package is automatically imported into all Java programs. A) java.lang B) java.default C) java.util D) java.java

java.lang

The ArrayList class is in the ________ package. A) java.lang B) java.util C) java.arraylist D) java.array

java.util

Layout containers provide methods for fine-tuning the way controls are arranged. A) True B) False

True

When an event takes place, the control responsible for the event creates an event ________. A) source B) firing C) handler D) object

object

You cannot use the == operator to compare the contents of ________. A) Boolean values B) strings C) objects D) integers

objects

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

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

If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString()); A) True B) False

True

Objects in an array are accessed with subscripts, just like any other data type in an array. A) True B) False

True

When programming in JavaFX, you should think of the GUI objects as nodes in a tree-like hierarchical structure known as a scene graph. A) True B) False

True

When the user selects an item in a ListView, a change event occurs. A) True B) False

True

Given the following code that uses recursion to find the factorial of a number, how many times will ELSE clause be executed if n = 5? Private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n-1); } A) 3 B) 4 C) 5 D) 6

5

The APPLICATION class's ________ method is the main entry point for a JavaFX application. A) start B) mainFX C) init D) addWIndow

Start

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A) public static void passMyArray[1][2]) B) public static void passMyArray(int[ ][ ]) C) public static void passMyArray(int[ 1, 2]) D) public static void passMyArray(int[ ],int[ ] myArray)

public static void passMyArray(int[ ][ ])

In the hexadecimal color value #CCAA99, the CC refers to the ________ color component? A) yellow B) green C) red D) blue

red

What method do you call to register an event handler with a Button control? A) onClickAction B) setAction C) setOnAction D) setOnClick

setOnAction

A recursive method must have which of the following? A) a control variable initialized to a starting value B) some way to control the number of time it repeats C) a statement that increments the control variable D) All of these

some way to control the number of time it repeats

Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0); What is true about the following statement? System.out.println(account); A) A compiler error will occur. B) A runtime error will occur C) The method will display unreadable binary data on the screen D) The ACCOUNT object's toString method will be implicitly called.

The ACCOUNT object's toString method will be implicitly called.

To build a menu system you must ________. A) create the Menu objects and register an event handler for each menu item object B) Add the MenuBar object to the scene graph C) create a MenuBar object D) All of these are necessary steps.

A) create the Menu objects and register an event handler for each menu item object B) Add the MenuBar object to the scene graph C) create a MenuBar object D) All of these are necessary steps.

A protected member of a class may be directly accessed by ________. A) methods in the same package B) methods of a subclass C) methods of the same class D) Any of these

A) methods in the same package B) methods of a subclass C) methods of the same class D) Any of these

To apply specific styles to all of the nodes in a scene, use the ________ selector. A) .top B) .root C) .stage D) .all

.root

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]? A) 1 through 15 B) 1 through 14 C) 0 through 15 D) 0 through 14

0 through 14

What will be the value of x[8] after the following code is executed? final int SUB = 12; int[ ] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; } A) 190 B) 180 C) 200 D) 170

180

What would be the result of executing the following code? Int[ ] x = {0, 1, 2, 3, 4, 5}; A) A compiler error will occur. B) The variable x will contain the values 0 through 5. C) An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created. D) An array of 6 values, all initialized to 0 and referenced by the variable x will be created.

An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created

One or more objects may be created from a(n) ________. A) method B) class C) field D) instance

class

A declaration for an enumerated type begins with the ________ key word. A) enum type B) enumerated C) ENUM D) enum

enum

A class specifies the ________ and ________ that a particular type of object has. A) relationships, object names B) fields, methods C) relationships, methods D) fields, object names

fields, methods

When a method's return type is a class, what is actually returned to the calling program? A) the value in the object that the method accessed B) a reference to an object of that class C) an object of that class D) nothing - the return type is simply for documentation in this situation

A reference to an object of that class

What does the following statement do? double[ ] array1 = new double[10]; A) It creates an instance of an array of ten DOUBLE values. B) It declares array1 to be a reference to an array of DOUBLE values C) it will allow valid subscripts in the range of 0 through 9. D) It does all of these

A) It creates an instance of an array of ten DOUBLE values. B) It declares array1 to be a reference to an array of DOUBLE values C) it will allow valid subscripts in the range of 0 through 9. D) It does all of these

When an object reference is passed to a method, the method may change the values in the object. A) True B) False

True

When you make a copy of the aggregate object and of the objects that it references, ________. A) you are performing a nested copy B) a compiler error will occur C) you are performing a deep copy D) you are performing a shallow copy

you are performing a deep copy

Declaring an array reference variable does not create an array. A) True B) False

Ture

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

final

To create a TextField control, you use the ________ class which is in the ________ package. A) TextBox, javafx.scene.control B) TextField, javafx.textfield C) TextField, javafx.scene.control D) TextField, javafx.text.control

TextField, javafx.scene.control

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for (i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } A) All the values in the array will be initialized to 10.0. B) All the values in the array except the first will be set to 10.0. C) The code contains a syntax error and will not compile. D) A runtime error will occur.

The code contains a syntax error and will not compile.

What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8; A) a = 13 B) a = 8 C) a = 10 D) a = 5

a = 5

Each array in Java has a public field named ________ that contains the number of elements in the array. A) limit B) length C) size D) capacity

length

Given the following styles, what size will the text of the label be? .root { -fx- font-size: 12pt; } .label { -fx- font-size: 18pt; } A) 15 pts B) This will cause an error because there are duplicate font-size styles. C) 12 pts D) 18 pts

18 pts

A class's responsibilities include ________. A) neither of these B) the things a class is responsible for knowing C) both of these D) the things a class is responsible for doing

B) the things a class is responsible for knowing C) both of these D) the things a class is responsible for doing

In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC A) ClassA B) ClassB C) ClassC D) all are interfaces

ClassC

When a subclass overloads a superclass method _________. A) both methods may be called with a subclass object B) neither method may be called with a subclass object C) only the superclass method may be called with a subclass object D) only the subclass method may be called with a subclass object

Both methods may be called with a subclass object

In a recursive program, the number of times a method class itself is known as t he _______. A) call count B) method heap C) depth of recursion D) cyclic identity

Depth of recursion

A(n) ________ is used as an index to pinpoint a specific element within an array. A) argument B) element C) subscript D) boolean value

subscript

Which of the following is an example of a lambda expression? A) int x = x * factor; B) IntCalculator multiplier = x -> x * factor; C) IntCalculator = new divider(x, 2); D) Any of these are examples of a lambda expression.

int x = x * factor;

Which of the following is a valid declaration for a ragged array with five rows but no columns? A) int[ ][ ] ragged = new int[ ][5]; B) int[ ][ ] ragged = new int[5][ ]; C) int[ ] ragged = new int[5]; D) int[ ][ ] ragged = new int[5];

int[ ][ ] ragged = new int[5][ ];

When you work with a ________, you are using a storage location that holds a piece of data. A) binary number B) numeric literal C) reference variable D) primitive variable

primitive variable

Which of the following statements declares Salaried as a subclass of PayType? A) public class PayType derives Salaried B) public class Salaried extends PayType C) public class Salaried derivedFrom(PayType) D) public class Salaried implements PayType

public class Salaried extends PayType

Which of the following statements will set a ListView control, puppyListView, to be 300 pixels high and 200 pixels wide? A) puppyListView.setPrefSize(200, 300); B) puppyListView.setSize(300, 200); C) puppyListView.setSize(200, 300); D) puppyListView.setPrefSize(300, 200);

puppyListView.setPrefSize(200, 300);

To add padding to an HBox you can call the ________ method. A) HBoxPadding B) setHboxPad C) setPadding D) SetHBoxPadding

setPadding

Which of the following statements creates a Slider with a range of 1 to 20 with a starting value of 1? A) Slider slider = new Slider(1.0, 20.0, 1.0); B) Slider slider = new slider(0.0, 20.0, 1.0); C) Slider slider = new Slider(1.0, 20); D) Slider slider = new Slider(0, 20, 1);

Slider slider = new Slider(1.0, 20.0, 1.0);

Which of the following statements creates an empty TextArea? A) TextArea textArea = new TextArea.textArea(""); B) TextArea textArea = new TextArea(); C) TextArea textArea = new TextArea(" "); D) TextArea = new textArea();

TextArea textArea = new TextArea();

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

overloaded

Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public double finalOrderTotal( ) { return orderAmount - orderAmount * orderDiscount; } } public class CustomerOrder { public static void main(String[ ] args) { Order order; int orderNumber = 1234; double orderAmt = 580.00; double orderDisc = .1; order = new Order(orderNumber, orderAmt, orderDisc); double finalAmount = order.finalOrderTotal(); System.out.printf("Final order amount = $%,.2f\n", finalAmount); } } A) 522.00 B) 528.00 C) 580.00 D) There is no value because the object, order, has not been created.

522.00

________ occurs when method A calls method B which in turn calls method A. A) Indirect recursion B) Linear recursion C) Dynamic recursion D) Direct recursion

Indirect recursion

In the following code, which line has an error? Line 1: public interface Interface1 Line 2: { Line 3: int FIELDA = 55; Line 4: public int methodA(double) { } Line 5: }

Line 4: public int methodA(double) { }

Any problem that can be solved recursively can also be solved iteratively, with a loop. A) True B) False

True

What does the following code do, assuming there is a variable that references a Scene object? myScene.getStylesheets( ).add("sceneStyles.css"); A) It adds a stylesheet named myScene to Scene. B) It adds a stylesheet named sceneStyles to Scene. C) The getStylesheets method gets sceneStyles.css and adds it to the to the myScene object. D) The getStylesheets method returns an object containing the scene's collection of stylesheets and that object's addmethod adds sceneStyles.css to the collection.

The getStylesheets method returns an object containing the scene's collection of stylesheets and that object's add method adds sceneStyles.css to the collection.

Which symbol indicates that a member is public in a UML diagram? A) + B) # C) - D) *

+

Select all that apply. It may be possible to simplify event handler code by using which of the following? - lambda expressions - anonymous inner classes - listener expressions - nested classes

- listener expressions - nested classes

In Java it is possible to write a method that will return ________. A) a reference to an object B) a string of characters C) a whole number D) Any of these

A) a reference to an object B) a string of characters C) a whole number D) Any of these

When an array is passed to a method ________. A) a reference to the array is passed B) it is passed just as any other object would be passed C) the method has direct access to the original array D) All of these are true

A) a reference to the array is passed B) it is passed just as any other object would be passed C) the method has direct access to the original array D) All of these are true

Which of the following problems can be solved recursively? A) greatest common denominator B) binary search C) Towers of Hanoi D) All of these.

A) greatest common denominator B) binary search C) Towers of Hanoi D) All of these.

An action that takes place while a program is running is a(n) _______. A) event object B) event C) event source D) event handler

Event

Programs that operate in a GUI environment must be ________. A) in color B) layout managers C) dialog boxes D) event driven

Event driven

A ComboBox differs only from a ListView in that a ComboBox must have a minimum of three items. A) True B) False

False

A GUI program automatically stops executing when the end of the main method is reached. A) True B) False

False

A method that gets a value from a class's field but does not change it is known as a mutator method. A) True B) False

False

A recursive method can have only one base case. A) True B) False

False

All methods in an abstract class must also be declared abstract. A) True B) False

False

An array can hold multiple values of several different types of data simultaneously. A) True B) False

False

Select all that apply. Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE]; It will allow valid subscripts in the range of 1 through 10. It creates an instance of an array of ten long values. It declares array1 to be a reference to an array of long values. It will allow valid subscripts in the range of 0 through 9.

It creates an instance of an array of ten long values. It declares array1 to be a reference to an array of long values. It will allow valid subscripts in the range of 0 through 9.

Select all that apply. Which of the following file types are supported by the Image class? JPEG PNG BMP GIF

JPEG PNG BMP GIF

The control that displays a list of items and allows the user to select an item from the list is the ________ control. A) ListView B) ArrayList C) SelectionList D) List

ListView

The ___________ class is used to create a menu bar. A) Menu B) MenuItem C) MenuBar D) Bar

MenuBar

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

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

The type of control normally used when you want the user to only be allowed to select one option from several possible options is the _______. A) Button B) CheckBox C) RadioButton D) Any of these

RadioButton

A method that calls itself is a ________ method. A) binary B) redundant C) recursive D) derived

Recursive

The process of connecting an event handler object to a control is called ______ the event handler. A) applying B) passing C) rendering D) registering

Registering

If the following is from the method section of a UML diagram, which of the statements below is true? + equals(object2:Stock) : boolean A) This is a private method that returns a boolean value. B) This is a public method that accepts a Stock object as its argument and returns a boolean value. C) This is a public method that returns a reference to a String object. D) This is a private method that receives two objects from the Stock class and returns a boolean value.

This is a public method that accepts a Stock object as its argument and returns a boolean value.

Adding RadioButton controls to a ________ object creates a mutually exclusive relationship between them. A) ToggleGroup B) MutualGroup C) RadioGroup D) ExcludeGroup

ToggleGroup

A class is not an object. It is a description of an object. A) True B) False

True

What does the following UML diagram entry mean? + setHeight(h : double) : void A) a private field called setHeight that is a double data type B) a public field called setHeight that is a double data type C) a private method with no parameters that returns a double data type D) a public method with a parameter of data type double that does not return a value

a public method with a parameter of data type double that does not return a value

Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"}; A) for (int i = 0; i < names.length(); i++) System.out.println(names[i].length); B) for (int i = 0; i < names.length; i++) System.out.println(names[i].length()); C) for (int i = 0; i < names.length; i++) System.out.println(names[i].length); D) for (int i = 0; i < names.length();i++) System.out.println(names[i].length());

for (int i = 0; i < names.length; i++) System.out.println(names[i].length());

Overloading means that multiple methods in the same class ________. A) have the same name but different return types B) perform the same function C) have the same name but different parameter lists D) have different names but the same parameter list

have the same name but different parameter lists

In the following code that uses recursion to find the factorial of a number, what is the base case? private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); } A) factorial(int n) B) else return n * factorial(n - 1); C) if (n == 0) return 1; D) Cannot tell from this code

if (n == 0) return 1;

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

method1 on Line 9

In order to leave 15 pixels of space in an HBox container, use which of the following statements? A) myhbox.setPadding.Insets(15); B) myhbox.setPadding(new Insets(15)); C) myhbox = setPadding(15); D) myhbox.setPadding(15);

myhbox.setPadding(new Insets(15));

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

#

The whole-part relationship created by object aggregation is more often called a(n) _______ relationship. A) inner class B) "has a" C) extra class D) inside class

"has a"

What type of relationship exists between two objects when one object is a specialized version of another object? A) "has a" B) "contains a" C) "is a" D) "consists of"

"is a"

Select all that apply. The SetStyle method is used to apply style rules directly to a JavaFX node. This method _______. - is considered a better way to add styles than using a stylesheet - allow you to pass only one style rule at a time, as a string argument - removes any styles that were previously applied to that node - allows you to pass multiple style rules as string arguments

- is considered a better way to add styles than using a stylesheet - allow you to pass only one style rule at a time, as a string argument

Which of the following creates a custom style class that will allow a Button control to appear with a blue background and yellow text? A) .blue-button { -fx- background: blue; -fx- text: yellow; } B) .blue-button { background-color: blue; text-fill: yellow; } C) .button-color { -fx- bgcolor: blue; -fx- textfill: yellow; } D) .button-color { -fx- background-color: blue; -fx- text-fill: yellow; }

.button-color { -fx- background-color: blue; -fx- text-fill: yellow; }

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

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

A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass. A) abstract B) overloaded C) static D) protected

Abstract

The BorderPane container always displays its content in five regions which are top, bottom, left, right, and center and each region must be used. A) True B) False

False

On a web page, the ______ specifies what information to display and the _______ specifies how that information should be displayed. A) CSS, HTML B) code, CSS C) HTML, JavaFX D) HTML, CSS

HTML, CSS

If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method? A) SavingsAccount.account20.getNumberOfAccounts( ); B) SavingsAccount.getNumberOfAccounts( ); C) account20.getNumberOfAccounts( ); D) getNumberofAccounts( );

SavingsAccount.getNumberOfAccounts( );

Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the fully-qualified name of the PINE enum constant? A) Tree.PINE B) enum.PINE C) enum.Tree.PINE D) PINE

Tree.PINE

A class's static methods do not operate on the fields that belong to any instance of the class. A) True B) False

True

ENUM constants have a toString method. A) True B) False

True

In the following code that uses recursion to find the greatest common divisor of a number, what is the base case? Public static int gcd(int x, int y) { if (x % y == 0) return y; else Return gcd(y, x % y); } A) else return gcd(y, x % y); B) if (x % y == 0) return y; C) gcd (int x, int y) D) Cannot tell from this code

if (x % y == 0) return y;

To display an image in a JavaFX application you must ________. A) include both the Image and the ImageView classes B) include either the Image or the ImageView class C) include either the setImage or the ViewImage class D) include both the setImage and the ViewImage classes

include both the Image and the ImageView classes

If you have defined a class, SavingsAccount, with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts? A) numAccounts = account20.numAccounts; B) numAccounts = SavingsAccount.numberOfAccounts; C) numAccounts = numOfAccounts; D) numAccounts = account20

numAccounts = SavingsAccount.numberOfAccounts;

If numbers is a two-dimensional array, which of the following would give the number of columns in row r? A) numbers[r].length B) numbers.length C) numbers.length[r] D) numbers[r].length[r]

numbers[r].length

A UML diagram does not contain ________. A) the method names B) the object names C) the class name D) the field names

the object names

When an object is passed as an argument to a method, what is passed into the method's parameter variable? A) the class name B) the values for each field C) the method names D) the object's memory address

the object's memory address

Which of the following is not a way a user can interact with a computer? A) console interface B) GUI C) command line D) All of these are ways for a user to interact with a computer.

All of these are ways for a user to interact with a computer.

Select all that apply. Which of the following are classes from the Java API? Package Random PrintWriter Scanner

Scanner

Which of the following ComboBox methods require a BOOLEAN argument? A) setValue B) setVisibleRowCount C) getValue D) setEditable

SetEditable

What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; } A) value contains the highest value in array1. B) value contains the sum of all the values in array1. C) value contains the lowest value in array1. D) This code would cause the program to crash.

This code would cause the program to crash.

A constructor is a method that is automatically called when an object is created. A) True B) False

True

What happens when the following code is executed? ComboBox<string> myComboBox = new ComboBox< > ( ); MyComboBox.getItems( ) .addAll(5, 10, 15, 20); A) The values 5, 10, 15, and 20 will be added to a ComboBox named myComboBox. B) a compiler error will occur C) A ComboBox displaying the numbers 5, 10, 15, and 20 will be created. D) The values 5, 10, 15, 20 will be converted to strings and added a new ComboBox named myComboBox.

a compiler error will occur

Which key word indicates that a class inherits from another class? A) final B) super C) extends D) implements

extends

One important difference between the command line interface and a GUI interface is that ________. A) in command line the background color of the monitor will always be black but in a GUI it can be any color B) users must type information in a command line interface but, when using a GUI, typing is never required C) in a GUI environment the user determines the order in which things happen while the user has no control over the order or events in a command line interface D) All of these are important differences.

in a GUI environment the user determines the order in which things happen while the user has no control over the order or events in a command line interface

A class that is defined inside another class is called a(n) ________. A) enumerated class B) nested class C) inner class D) helper class

inner class

When an object is created, the attributes associated with the object are called ________. A) instance fields B) instance methods C) class instances D) fixed attributes

instance fields

Methods that operate on an object's fields are called _________. A) instance methods B) public methods C) instance variable D) private methods

instance methods

When a field is declared static there will be ________. A) only one copy of the field in memory B) two reference copies of the field for each method in the class C) a copy of the field in each class object D) a copy of the field for each method in the class

only one copy of the field in memory

Enumerated types have the ________ method which returns the position of an enum constant in the declaration list. A) index B) location C) ordinal D) position

ordinal

Which of the following statements correctly specifies two interfaces? A) public class ClassA implements Interface1, Interface2 B) public class ClassA implements (Interface1, Interface2) C) public class ClassA implements Interface1 | Interface2 D) public class ClassA implements [Interface1, Interface2]

public class ClassA implements Interface1, Interface2

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A) public static void passArray(int[1],[2]) B) public static void passArray(int[1,2]) C) public static void passArray(int [ ][ ]) D) public static void passArray(int[ ], int[ ])

public static void passArray(int [ ][ ])

Static methods can only operate on ________ fields. A) static B) global C) local D) instance

static

The scope of a private instance field is ________. A) the instance methods of the same class B) inside the class but not inside any method in that class C) the method in which it is defined D) inside the parentheses of a method header

the instance methods of the same class

A partially filled array is normally used ________. A) with an accompanying parallel array B) when only a very small number of values need to be stored C) when you know how many elements will be in the array but not what the values are D) with an accompanying integer value that holds the number of items stored in the array

with an accompanying integer value that holds the number of items stored in the array

To compare two objects in a class, ________. A) write an equals method that will make a field by field compare of the two objects B) use the == operator (for example, object1 == object2) C) This cannot be done since objects consist of several fields. D) write a method to do a byte-by-byte compare of the two objects

write an equals method that will make a field by field compare of the two objects

What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x; A) x[ ] = {23, 55, 83, 19} and y[ ] = {23, 55, 83, 19} B) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24} C) x[ ] = {36, 78, 12, 24} and y[ ] = {23, 55, 83, 19} D) Nothing. This is a compile error.

x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24}

What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for (int i = 0; i < SUB; i++) { x[i] = y; y += 5; } A) 55 B) 50 C) 65 D) 60

60

If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector. A) True B) False

False

Java limits the number of dimensions that an array can have to 15. A) True B) False

False

Which of the following is not true about static methods? A) They are often used to create utility classes that perform operations on data but have no need to store and collect data. B) They are created by placing the key word static after the access specifier in the method header. C) It is necessary for an instance of the class to be created to execute the method. D) They are called directly from the class.

It is necessary for an instance of the class to be created to execute the method.

What does the following statement do? Image puppy = new Image("file:C:\\images\terrier.jpg"); A) It loads an image file named terrier.jpg which is found in the images folder on the user's C-drive. B) It creates an instance of the ImageView class with the terrier.jpg file passed to the constructor. C) It loads an image named "images\terrier.jpg" and stores the image in the Image variable. D)Nothing; it is not possible to include a path to a file when using the Image class.

It loads an image file named terrier.jpg which is found in the images folder on the user's C-drive.

A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method. A) True B) False

True

A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem. A) True B) False

True

A single copy of a class's static field is shared by all instances of the class. A) True B) False

True

An event object is created when an event takes place. A) True B) False

True

What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String> (); A) It specifies that only STRING objects may be stored in the ArrayList object. B) It specifies that String objects may not be stored in the ArrayList object. C) It specifies that the ArrayList will be converted to a STRING array. D) It specifies that everything stored in ArrayList object will be converted to STRING object.

It specifies that only STRING objects may be stored in the ArrayList object.

If the following is from the method section of a UML diagram, which of the following statements is true? + add(object:Stock) : Stock A) This is a public method named STOCK that adds two objects. B) This is a private method named STOCK that adds two objects. C) This is a public method named add that accepts and returns references to objects in the STOCK class. D) This is a private method named ADD that accepts and returns objects of the STOCK class.

This is a public method named ADD that accepts and returns refrences to objects in the STOCK class.

An ArrayList object automatically expands in size to accommodate the items stored in it. A) True B) False

True

An abstract class is not instantiated itself but serves as a superclass for other classes. A) True B) False

True

When the THIS variable is used to call a constructor__________. A) it must be the last statement in the constructor making the call B) it can be anywhere in the constructor making the call C) it must be the first statement in the constructor making the call D) None of these. You cannot use the THIS variable in a constructor call.

it must be the first statement in the constructor making the call

Methods that operate on an object's fields are called _______. A) public methods B) private methods C) instance methods D) instance variable

Instance methods

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

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

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

ClassA

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

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

Select all that apply. Given the statement shown below, which of the following statements are true? Scene scene = new Scene(hbox, 100, 500); The height of the scene will be 100 pixels. The width of the scene will be 100 pixels. A Scene object named scene will be created. The root node is hbox.

The height of the scene will be 100 pixels. A Scene object named scene will be created. The root node is hbox.

An instance of a class does not have to exist in order for values to be stored in a class's static fields. A) True B) False

True

A reference variable stores a(n) ________. A) object B) string C) binary encoded decimal D) memory address

memory address

You cannot use the fully-qualified name of an enum constant for ________. A) an argument to a method B) a boolean expression C) a case expression D) Any of these

a case expression

To return an array of long values from a method, which return type should be used for the method? A) long B) long[ARRAY_SIZE] C) array D) long[ ]

long[ ]

To indicate the data type of a variable in a UML diagram, you enter ________. A) the variable name followed by a colon and the data type B) the data type followed by the variable name C) the class name followed by the variable name followed by the data type D) the variable name followed by the data type

the variable name followed by a colon and the data type

You can write a super statement that calls a superclass constructor but only in the subclass's constructor. A) True B) False

True

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

Line 11

What would be the result after the following code is executed? int[ ] numbers = 40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = i; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; } A) The VALUE variable will contain the average of the values in the numbers array. B) The VALUE variable will contain the sum of all the values in the NUMBERS array. C) The VALUE variable will contain the highest value in the NUMBERS array. D) The VALUE variable will contain the lowest value in the NUMBERS array.

The VALUE variable will contain the lowest value in the NUMBERS array.

Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members. A) True B) False

True

For this question, assume myView references an ImageView object. In order to preserve the image's aspect ratio (so it does not appear stretched or distorted), you should use which of the following? A) myView.setPreserveRatio(false); B) Either (a) or (c) would work. C) myView.setPreserveRatio(true); D) myView.setPreserveRatio();

myView.setPreserveRatio(true);

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

ClassB

Given the following code, which statement is true? Public class ClassB implements ClassA{ } A) ClassB must override each method in ClassA B) CLassB inherits from ClassA C) ClassA must override each method in ClassB D) ClassA inherits from ClassB

ClassB must override each method in ClassA

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

Line 8

Given the following two-dimensional array declaration, which statement is true? int[ ][ ] numbers = new int[6][9]; A) The numbers array has 6 rows and 9 columns. B) The numbers array has 6 columns and 9 rows. C) The numbers array has 54 rows. D) The numbers array has 15 rows.

The numbers array has 6 rows and 9 columns.

What would be the result after the following code is executed? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 1; i < numbers.length; i++) value += numbers[i]; A) The value variable will contain the lowest value in the numbers array. B) The value variable will contain the average of all the values in the numbers array. C) The value variable will contain the sum of all the values in the numbers array. D) The value variable will contain the highest value in the numbers array.

The value variable will contain the sum of all the values in the numbers array.

If you have two RadioButtons (dogRadio and catRadio), how should you code them to create a mutually exclusive relationship? A) dogRadio.setToggleGroup(); catRadio.setToggleGroup(): B) ToggleGroup radioGroup = new ToggleGroup( ); dogRadio.setToggleGroup(radioGroup); catRadio.setToggleGroup(radioGroup): C) ToggleGroup radioGroup = new radioGroup(); dogRadio.setToggle(radioGroup); catRadio.setToggle(radioGroup): D) ToggleGroup dogRadio = new ToggleGroup(); ToggleGroup catRadio = new ToggleGroup();

ToggleGroup radioGroup = new ToggleGroup( ); dogRadio.setToggleGroup(radioGroup); catRadio.setToggleGroup(radioGroup):

Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created. A) True B) False

True

If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector. A) True B) False

True

If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. A) True B) False

True

Recursion can be a powerful tool for solving repetitive problems and is an important topic in upper-level computer science courses. A) True B) False

True

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable. A) True B) False

True

The Pos type must be imported from the javafx.geometry package. A) True B) False

True

The Towers of Hanoi is a mathematical game that is often used in computer science textbooks to illustrate the power of recursion. A) True B) False

True

The key word this is the name of a reference variable that an object can use to refer to itself. A) True B) False

True

The actions performed by the JVM that take place with each method call are sometimes referred to as ________. A) retention B) allocation C) overhead D) overflow

overhead

If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method. A) implements B) overloads C) inherits D) overrides

overrides

In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance. A) polymorphic B) static C) public D) dynamic

polymorphic

In the ________, the problem must be reduced to a smaller version of the original problem. A) partition case B) recursive case C) lessening case D) base case

recursive case

Select all that apply. Which of the following are possible selection nodes available to the ListView control? single interval selection mode multiple selection mode single selection mode multiple interval selection mode

single selection mode multiple interval selection mode


Related study sets

Sociology Final Exam (Building Blocks: Social Institutions)

View Set

Biochemistry Carbohydrates - by MHashi, Biochem ch 8, Ch. 9 Lehninger biochem, Chapter 10 multiple choice, Chapter 7 Biochemistry, Biochem ch 6, Old Test 3; June 2010, My Test 2, Quiz 1, Cell Components, Quiz 2, Quiz 3, Quiz 4, Quiz 5, Old Test 1, Ma...

View Set

Unit 3 American History and Unit 4 American History

View Set

Forms of Business Organizations (Sole Proprietorships, Partnerships, Corporations) 2B

View Set