CS1331 QUIZZES

Ace your homework & exams now with Quizwiz!

Which of the following would instantiate an array named library that can hold at most 8 objects of type Book?

1. Book[] library = new Book[8]; 2. Book library[]; library = new Book[8];

Which of the following is true regarding Wrapper classes in Java?

1. If a primitive is assigned to a variable of the corresponding wrapper class, Java will automatically convert it. 2. Variables of wrapper class types can be null.

Which of the following most accurately describes the Math class?

1. It contains all static methods and constants and we can use them in our programs (e.g. Math.abs() and Math.PI) 2. It is in the java.lang package

Why must we be careful when writing code to remove nodes at a specific index from LinkedLists?

1. It is hard to find the correct node we are trying to remove because it is not indexed 2. If we do not reset the head/tail pointers then our future traversals may be incorrect 3. If we do not properly reset the next/previous pointers we can lose part of the list by accident

Which of the following is true about a constructor?

1. It must have the same name as the name of the class. 2. It can have any number of parameters.

Which of the following is true regarding static methods?

1. Non static methods can call static methods without erroring. 2. Static methods can be called using the class name OR using an instance of the class itself.

-Snack is an abstract class and Chips and Ruffles are both concrete classes. - Ruffles is a subclass of Chips, and Chips is a subclass of Snack Which of the following will not compile?

1. Ruffles c = new Chips(); 2. Snack s = new Snack();

Checked exceptions means that the compiler knows at compile time that there is code that could potentially throw a checked Exception. Which of these are valid ways to appease the compiler if you are throwing an IOException?

1. Use a try-catch block 2. Indicate at the method header that it throws IOException

Select all of the true properties of File objects in Java

1. You must either handle FileNotFoundExceptions within the method in which you create a file or you must propagate it to another method (adding throws to method header). 2. Can instantiate File objects with pathname.

Which of the following are legal headers for an abstract class?

1. abstract class Dhruv{} 2. public abstract class Dhruv{}

Which of the following is considered an appropriate header for overriding the equals method within a Dog class?

1. public boolean equals (Object other) 2. public boolean equals (Object o)

Two int variables x and y hold the values 3 and 2, respectively. When is the value held in w after the following line of code is executed? double w = x / y

1.0

If: int s = 10; int t = 3; int u = 7; What is the value of: System.out.println(s * (t + u) / s);

10

What is the value of the counter after the following code is executed? int counter = 2; while (counter < 10) { counter++; } System.out.println("The value of counter is: " + counter);

10

What would be the value of the last index of the array nums if the following code was run? int[] nums = new int[6]; int i = 0; while (i < nums.length) { nums[i] = 2 * i; i++; }

10

What gets printed? int[][] twoDim = {{1, 2}, {3, 4}}; System.out.println(twoDim[0][1]);

2

If: int s = 10; int t = 3; int u = 7; What is the value of: System.out.println((s * t + u) / s);

3

If: int s = 10; int t = 3; int u = 7; What is the value of: System.out.println(s * t + u / s);

30

What is the output of the following code snippet? String myString = "33333" myString.replace("3", "e"); System.out.println(myString);

33333

What is the value of x after the following snippet of code is run? int a = 9; int b = 2; double x = (double) a / b;

4.5

What is the output of the following code? int x = 5; int y = 2; System.out.println(x + y * 5/3);

8

How many potential matches are eliminated after the second iteration (i.e. second pass) of the binary search algorithm for the value of 94? [98, 94, 88, 79, 76, 63, 53, 32, 31, 29, 28]

9

What is printed by the following code? int days = 9; int daysLeft = days--; System.out.println(daysLeft); System.out.println(days);

9 8

Which of the following best describes the relationship between a class and an object?

A class is the "blueprint" or cookiecutter from which objects are created.

Suppose the xMethod() is invoked from a main method in a class as follows, xMethod() is _______ in the class.

A static method.

What is true about Arrays?

After instantiating a new array, the size is fixed.

Which of the following ArrayList declarations will not compile? Assume that

ArrayList<> arr = new ArrayList<>();

Which type of pane best matches the following description: Places nodes in the top, bottom, left, right, and center regions.

BorderPane

Analyze the following code. Does autoboxing or unboxing occur? Integer a = 100; int b = a; System.out.println(a + b);

Both

We can use type bounds to provide a way to control what types a user can pass in when they use a generic class. In order to introduce an upper bound, we use the ____ keyword.

Extends

What keyword is used to make a class inherit from another class?

Extends

The following code is legal: int myId = 1234; myId = true;

FALSE

T/F A consequence of type erasure is that we can instantiate a generic array, such as T myArray[] = new T[].

False

T/F An ArrayList can hold primitive values and objects.

False

T/F Every class that implements Iterator must also implement Iterable.

False

T/F Java supports multiple inheritance (i.e. a single class can inherit from two or more classes)

False

T/F Only GUI programs such as JavaFX use event-driven programming

False

T/F You do not need to create an ImageView object in order to show an image in the JavaFX GUI

False

Which of the following statements are correct?

Generics allow for code reuse. Generics can help detect type errors at compile time. Generics can help avoid cumbersome castings.

What is the output of the following code: Scanner myScanner = new Scanner(System.in); String dataOne = myScanner.next(); String dataTwo = myScanner.nextLine(); System.out.println(dataOne); System.out.println(dataTwo); // At the terminal, the user types in: "Hi! I take CS1331!"

Hi! I take CS1331!

What is Big O?

How long an algorithm takes to run relative to its input size.

The ______ interface defines the manner in which elements in collections that implement it are sequentially accessed.

Iterator

What is the best Big O approximation of binary search?

O(log n)

-Snack is an abstract class and Chips and Ruffles are both concrete classes. - Ruffles is a subclass of Chips, and Chips is a subclass of Snack What is the dynamic type of s2? Chips s2 = new Ruffles();

Ruffles

-Snack is an abstract class and Chips and Ruffles are both concrete classes. - Ruffles is a subclass of Chips, and Chips is a subclass of Snack What is the static type of s1 Snack s1 = new Ruffles();

Snack

We can use type bounds to provide a way to control what types a user can pass in when they use a generic class. In order to introduce a lower bound, we use the ____ keyword.

Super

Why are visibility modifiers necessary?

They can be used to selectively hide portions of the class, fulfilling the fundamental OOP concept of encapsulation.

All exceptions occur at the runtime of your program.

True

If a collection implements Iterable, you can use a for each loop on it.

True

T/F A concrete subclass of an abstract class must implement all of the abstract class's abstract methods.

True

T/F An ArrayList will automatically resize once the capacity is reached.

True

T/F Constants can be ignored in Big O notation

True

T/F Every class extends from the Object class in Java (T/F)

True

T/F Every primitive type has a corresponding wrapper class.

True

T/F When constructor chaining, you should chain from the lower argument constructor to the higher argument constructor

True

What is the output of the following code snippet? String fruit1 = "Pear" String fruit2 = "Pear"; String fruit3 = new String("Pear"); System.out.println(fruit1 == fruit2); System.out.println(fruit2 == fruit3); System.out.println(fruit2.equals(fruit3));

True False True

Which type of pane best matches the following description: Aligns nodes vertically in a single column.

VBox

Will the following program terminate? int balance = 10; while (true) { if (balance < 9) break; balance = balance - 9; }

Yes

Which of the following are invalid identifiers?

a++, #acb, 9*3

Which of the following declares a variable named cold and correctly assigns the value of true to it?

boolean cold = true;

Which of the following correctly converts the below for-loop into a while-loop? for (int count = 0; count < 12; count++) { System.out.println("Loops and more loops!"); }

int count = 0; while (count < 12) { System.out.println("Loops and more loops!"); count++; }

Which of the following is considered an appropriate header for overriding the toString method within a Dog class?

public String toString()

Which of the following is an acceptable header for a generic class Animal that takes in one type: T. We only want to accept T's that implement the Comparable interface.

public class Animal<T extends Comparable>

Given the calculateGraduation method header below: public int calculateGraduation(int year) Which of the following is a valid header for a method that overrides the calculateGraduation method?

public int calculateGraduation(int year)

Which of the following method headers is correctly indicated that the method can throw a FileNotFoundException, if one occurs?

public void errorMethod() throws FileNotFoundException

Which of the following method headers correctly overrides the start() method found within the Application class?

public void start(Stage primaryStage)

Which of the following a visibility modifiers?

public, private

Which of the following will randomly generate an integer between 1 and 10 inclusive? Assume that a Random object named "rand" has already been declared and initialized.

rand.nextInt(10) + 1;

What is automatically inserted into the line indicated by the comment below? public class CoffeeShop { public CoffeeShop(String name) { //What goes in this line? this.name = name; profits = 0; } }

super();


Related study sets

SPC Level 2 Exam 2- Anemia Adaptive Quiz

View Set

Ian Sommerville Exams Series Quizlet

View Set

ISNS 2329 Earthquakes and Volcanos: Unit 3

View Set