CSE 205 Spring A Final
Which of the following are Java primitive data types? Array float char double class Random String int Math boolean
float char double String int boolean
Which keyword is used in Java to create an object?
new
Which of the following would correctly declare and instantiate an array of 7 ints? int[4] values = new int[4]; int[] values = int[5]; int[6] values = new int[6]; int [] values = int[6]; None of these
none of these
Evaluate the expression: 4 >= 3
true
Evaluate the logical expression: ! false && true
true
An object's attributes are implemented as _____.
variables
Which of the following are Java identifiers? SpEcIaL_vAlUe Test Variable size! x TestVariable tax1 variable-2 AGE2 3_TAX Age_2
x TestVariable tax1 AGE2
Evaluate the following code: class Foo { public int i = 31; public Foo(int i) { this.i = i; } } ... Foo x = new Foo(5), y = new Foo(83); x.i = y.i; y.i = 51; System.out.print(x.i);
5
What will this small program output? class Main { public static void foo() { int x = 5; System.out.println(x); } public static int x = 12; public static void main(String args[]) { x = 24; foo(); }
5
In Java a variable must: A. be initialized before it can be used B. be deleted before it can be used C. be normalized before it can be used D. be declared before it can be used E. None of these
D
Which of the following correctly demonstrates the use of an array initializer list? Choose all. A. int[] my_array = [1, 2, 3, 4, 5]; B. none of these C. int my_array = new {1, 2, 3, 4, 5}; D. int[] my_array = {1, 2, 3, 4, 5}; E. int my_array = (1, 2, 3, 4, 5);
D
To help us collect information from the user through the keyboard in Java, we use a(n): A. user_input object B. lambda C. while loop D. input function E. none of these
E
T / F A sub-class may inherit methods or instance variables from its super class but not both.
False
T / F A value type variable can store a null reference in Java.
False
Methods used to access an object's private data are called ______ .
Getters and Setters
Evaluate the following code to determine what value will be at the bottom of the stack after the code completes. MyStack<Integer> s = new MyStack<Integer>(); s.push(16); s.push(65); s.push(90);
16
What is the output of this Java program? class Driver { public static void main(String args[]) { int a = 2; int b = 3; int c = 7; int x = 1; if (a < 3) { x = x + 200; } if (b < 2) { x = x + 30; } if (c > 8) { x = x +7; } System.out.print(x);
201
Evaluate the following code to determine the output. MyQueue<Integer> q = new MyQueue<Integer>(); q.add(22); q.add(65); q.add(73); System.out.println(q.remove());
22
Given the following int variables, a = 6, b = 7, c = 3, d = 12, evaluate the following expression: a * b / c + d
26
What is the output of this Java program? class Driver { public static void main(String args[]) { int a = bar(2); int b = foo(a); } static int foo(int a) { System.out.print(a); a = bar(a - 0); return a; } static int bar(int a) { System.out.print(a); return a + 4; } }
266
Evaluate the following code to determine the output. MyStack<Integer> s = new MyStack<Integer>(); s.push(34); s.push(69); s.push(71); s.pop(); s.pop(); System.out.println(s.pop() );
34
Evaluate the following code to determine what value will be at the front of the queue after the code completes. MyQueue<Integer> q = new MyQueue<Integer>(); q.add(38); q.add(42); q.add(83);
38
Evaluate the code to determine the output. MyStack<Integer> s = new MyStack<Integer>(); s.push(23); s.push(26); s.push(13); System.out.println(s.pop() + s.pop() );
39
Which of the following have the data type float? -3 true '\n' "true" 3.0 3.14 123 3f "3.0" false 'a' 3.14f
3f 3.14f
What will this small program output? int a = 9; int b = 5; int c = 10; int x = 7; boolean y = a > b; boolean z = c < b; if (y || z) { x = 4; } else { x = 7; } System.out.print(x);
4
Given the following declaration: int[][] values = { {2, 68, 26, 62} {21, 92, 44, 51} {79, 37, 83, 99} } Evaluate: values[1][2]
44
Evaluate the following code to determine the output. MyStack<Integer> s = new MyStack<Integer>(); s.push(16); s.push(29); s.push(19); System.out.println(s.pop() + s.pop() );
48
What is the output of this Java program? class Driver { public static void main(String args[]) { int[] x = {2, 6, 2, 4, 2}; int n = x.length; for (int j = n-1; j > 0; j--) { x [ j ] = x [ j -1 ]; } for (int j = 2; j < n; j++) { System.out.print( x [ j ]); }
624
What is the output of this Java program? class Driver { public static void main(String args[]) { foo(6); bar(5); } static void foo(int a) { System.out.print(a); } static void bar(int a) { foo(a + 1); System.out.print(a); }
665
Given the following declaration: int[] values = {66, 13, 34, 87, 99, 76, 20, 36, 19, 96} Evaluate: values[5]
76
When there are no more remaining references to an object, the object will be: A. destroyed B. instantiated C. created D. initialized E. none of these
A
Which object oriented element is used to help ensure that "an object should have complete authority over its responsibilities"? A. data hiding B. message passing C. polymorphism D. composition E. inheritance
A
In Java class members are declared with the keyword: A. void B. static C. local D. global
B
Which of the following are good analogies for classes and objects? A. none of these B. cookie cutters and cookies C. data types and expressions D. variables and functions E. blueprints and buildings
B, E
Write a line of Java code that will declare a boolean variable named group that is initialized to the value true.
Boolean group = true;
A default constructor takes ___ argument(s). A. any number of B. 2 C. 0 D. 1
C
All of the Java primitive types are: A. expression types B. class types C. value types D. reference types E. none of these
C
Which of the following would always cause an ArrayIndexOutOfBoundsException? Choose all that apply. A. for (int j = 0; j < values.length - 1; j++) { values[j]++; } B. for (int j = 1; j < values.length - 1; j++) { values[j]++; } C. for (int j = values.length; j >= 0; j--) { values[j]++; } D. for (int j = 0; j <= values.length; j++) { values[j]++; } E. for (int j = values.length; j > 0; j--) { values[j]++; } F. for (int j = values.length - 1; j > 0; j--) { values[j]++; } G. for (int i = 1; j < values.length; j++) { values[j]++; }
C, D, E
Which of the following would correctly declare and instantiate a 2D array with a total of 18 ints? A. int[9][2] values = new int; B. int[][] values = new int; C. int[][] values = new int[2][9]; D. int[][] values = new int[9][2]; E. int[3,6] values = int[18]; F. int[3] values = new int[6]; G. int[3][6] values = new int; H. int[] values = int[6,3]; I. int[,] values = new int[3,6]; J. int[,] values = new int[2,9] K. int[][] values = new int[3][6]; L. None of these
C, D, K
Which object oriented relationship is used to define a "has a" relationship? Polymorphism Data Hiding Composition Inheritance Message Parsing Encapsulation
Composition
Given the class definition, which statements would instantiate an object of this class? public Cat() public Cat(int initAge, String initName) A. String yourCat = new Cat(3, "Fifi") B. Cat myCat = Cat(); C. Cat myCat = new Cat("Fifi"); D. none E. new Cat myCat = Cat(); F. new Cat myCat = Cat(5, "Fwuffy"); G. new yourCat = Cat(3, "Fifi"); H. new Cat myCat = Cat(); I. Cat yourCat = new Cat("Fifi", 3); J. Cat yourCat = Cat(3, "Fifi");
D
T / F A "is a" relationship is implemented by inheritance
True
T / F A Stack is a Last In First Out (LIFO) data structure.
True
T / F A class from which you can create objects is called a concrete class.
True
T / F A method that may throw a checked exception must either catch that exception or declare that it throws an exception in its header.
True
T / F A name defined in an outer scope is also available in all blocks nested inside that scope.
True
T / F A sub-class may inherit methods and instance variables from its super class, and may also implement its own methods and declare its own instance variables.
True
T / F All methods in a Java interface must be abstract.
True
T / F All methods in an interface are automatically public.
True
T / F Any iterative algorithm can be written recursively.
True
T / F Data hiding makes encapsulation work.
True
T / F Encapsulation is about assigning responsibilities to objects.
True
T / F If you declare a parameterized constructor in your class, the compiler will not create a default constructor for you.
True
T / F In a Binary Search Tree, all elements to one side of a node are < that node's value, and all elements to the other side are > that node's value.
True
T / F Members that are protected in the super class are visible in the derived class.
True
T / F Stacks and Queues can be implemented as ArrayLists or LinkedLists.
True
T / F The "super" keyword is used in the subclass constructor to call a specific super class constructor.
True
T / F The benefit of data hiding is that we can make an object truly responsible for what it knows and what it does.
True
T / F The finally block of a try/catch structure will execute if no exception occurs in the try block.
True
T / F We cannot delete individual elements from an array in Java.
True
When the following expression is evaluated, the result will be what Java data type? 17f * 19 int float double boolean char String none of these
float
Evaluate the expression: 6 + 2 <= 4 || 11 - 3 > 8
false