CPSC 1210 Final

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

Which of the following are valid Java identifiers? Choose all that apply. $pring_2017 Spring-2017 Spring! Spring2017 2017Spring

$pring_2017 Spring2017

Which character below is not allowed in an identifier? a) $ b) 2 c) & d) q e) _

&

Iteration

(repetition) - statements that allow us to execute a statement (or block of statements) iteratively or repeatedly, as long as some condition is true; i.e., loop through the statement or block of statements Examples: while, do-while, for statements (a.k.a. loops)

Which one of the following Java comment forms can span multiple lines, but is not a Javadoc comment? All of the above /** the comment */ None of the above // the comment /* the comment */

/* the comment */

Which one of the following Java comment forms can span only one line (i.e., it cannot span multiple lines)? // the comment All of the above /** the comment */ /* the comment */ None of the above

// the comment

After the following lines of code are executed, what is the value of x?(assume correct imports)DecimalFormat df = newDecimalFormat("#,###.000#");String x = df.format(1000.1);

1,000.100

What is the value of myNum after the following code is executed? double myNum = 21 % 2; 1.0 1 10.5 10 None of the above

1.0

ArrayList<String> shapes = new ArrayList<String>(); shapes.add("Circle"); shapes.add("Square"); shapes.add("Triangle"); int before = shapes.indexOf("Square"); shapes.remove(1); int allShapes = shapes.size(); int after = shapes.indexOf("Circle"); In the code above, what is the value of allShapes? Assume all proper imports have been made.

2

What value is returned when example(20, 2, 3)is called?

2

After the code has completed, what is the value of x?

2.0

After all lines have executed, what does mascots.size() return?

3

What is the value of x after the following code is executed? int x = 0; x = 13 % 2 * 3;

3

What value is returned when example(3, 2, 3)is called?

3

int = 0; for (int i = 0; i < 3; i ++) { switch x { case 0: x ++; break; case 1: x = x * 2; break; default; x != i; } } System.out.println (x); How many times will the body of the for loop be executed? 2 3 4 5 Infinite loop

3

int i = 0; x = 0; y = 0; do { switch (y) { case 1: y ++; case 2: x ++; default; x += 2; y ++; } i++; } while (i < 3); How many times does the body of the loop execute? (Note that the code in the image is the same as the previous question) 2 3 4 5 None of the above

3

int i = 0; x = 0; y = 0; do { switch (y) { case 1: y ++; case 2: x ++; default; x += 2; y ++; } i++; } while (i < 3); How many times is the variable i checked? (Note that the code in the image is the same as the previous question) 2 3 4 5 None of the above

3

int i = 0; x = 0; y = 0; do { switch (y) { case 1: y ++; case 2: x ++; default; x += 2; y ++; } i++; } while (i < 3); What is the value of i after the loop terminates? 0 1 2 3 4

3

How many bits are used to store a value of type int?

32

int = 0; for (int i = 0; i < 3; i ++) { switch x { case 0: x ++; break; case 1: x = x * 2; break; default; x != i; } } System.out.println (x); What is printed after the loop terminates? (Note that the code in the image is the same as the previous question) 4 7 9 17 None of the above

4

int i = 0; x = 0; y = 0; do { switch (y) { case 1: y ++; case 2: x ++; default; x += 2; y ++; } i++; } while (i < 3); What is the value of y after the loop terminates? (Note that the code in the image is the same as the previous question) 3 4 5 6 None of the above

4

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } How many methods does the Circle class have? 0 1 2 3 4

4

public void example(int x, int y) { while (x < 5) { if (x == y || x == 1) { } else if (x == y && y == 1) { y += x; } else { y--; } x++; } System.out.printLn(x + "--" + y); } In the code above (repeated from the previous question), how many times will the body of the while loop be executed when example(-1, -1) is called?

6

After the code has completed, what is the value of y?

6.0

What is the value of resultValue after the following code is executed? int resultValue = 8; do { resultValue++; } while (resultValue < 6);

9

After the code has completed, what is the value of z?

9.0

One day you find that your web browser crashes when you press the "refresh" button over and over. What type of error has most likely occurred?

A run-time error

Which of the following is used to concatenate a String? a.+ b.-- c.\n d.\r\n e.None of the above

A: +

Assume that result is a double and x, y and z are of type int equal to 50, 20 and 6 respectively. What is the value of result after the assignment statement below?result = x / y / z; a) 0.0 b) 12.0 c) 16.0 d) A syntax error as this is syntactically invalid e) A run-time error because this is a division by 0

A: 0.0

What is the output after the following code is executed? System.out.print("Auburn" + " over Bama\n"); System.out.println(84 + " - " + 64); Auburn over Bama 84 - 64 Auburn over Bama 84 - 64 Auburn over Bama 20 Auburn over Bama 20 None of the above

Auburn over Bama 84 - 64

The relationship between a class and an object is best described as a) classes are instances of objects b) objects are instances of classes c) objects and classes are the same thing d) classes are programs while objects are variables e) objects are the instance data of classes

B: Objects are instances of classes

What belongs in blank __17__?

B: String

Given the following, what is the result of running the following program? class Bool { public static void main(String [] args) { boolean b1 = true; boolean b2 = false; boolean b3 = true; if ( b1 && b2 || b2 && b3 || b2 ) System.out.print("Auburn "); if ( b1 && b2 || b2 && b3 || b2 || b1 ) System.out.println("Tigers"); } } a) Auburn b) Tigers c) Auburn Tigers d) No output is produced e) Compilation error

B: Tigers

Which of the following reserved words will skip the remainder of the code in an iteration of a loop and exit the loop? a. static b. break c. private d. continue e. final

B: break

If i is an int and x is a double, all of the following are legal except which assignment statement? a) x = i; b) i = x; c) x = (double) i; d) i = (int) x; e) i = i * (int) x;

B: i = x;

Which one of the following violates encapsulation?

B: name

Suppose you wish to provide an accessor method for a boolean instance variable called finished. What method header should be used? a) public void getFinished() b) public boolean getFinished() c) public boolean setFinished() d) public void setFinished() e) none of the above

B: public boolean getFinished()

After all lines have executed, what does mascots.get(2) return?

Bully

Given the following assignment statement, which of the following answers indicates the order that the operators will be applied? a = b * (c + d) / e - f; a) *, /, +, - b) *, +, /, - c) +, *, /, - d) +, /, *, - e) +, -, *, /

C: +, *, /, -

What is the value of answer after the following statements: double x = 4; int i = 5; double answer = (x/i) * 2; a) 0 b) 1 c) 1.6 d) 2 e) none of the above (will not compile)

C: 1.6

What belongs in blank __13__?

C: Dog

Since you cannot take the square root of a negative number, which of the following would ensure that the value of x is non-negative and find its square root? a) Math.sqrt(x*x); b) Math.sqrt((int) x); c) Math.sqrt(Math.abs(x)); d) Math.abs(Math.sqrt(x)); e) Math.sqrt(-x);

C: Math.sqrt(Math.abs(x));

Which one of the following is an accessor method?

C: getName

Consider the declaration and statement: Account x = new Account(); Which of the following is most accurate after the statement is executed? a) x contains an int value. b) x contains an object of the Account type. c) x contains a reference to the Account object. d) You can assign an int value to x. e) none of the above

C: x contains a reference to the Account object

One way to convert one numeric type to another numeric type is by ______.

Casting

If you want to output the text "hi there", including the quote marks, which of the following could do that? a) System.out.println("hi there"); b) System.out.println(""hi there""); c) System.out.println("\"hi there"); d) System.out.println("\"hi there\""); e) None of above, since it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output.

D

What will be the value of x after the following statements? int y = 5; int z = 10; int x = y * (-z + 2) / 2; a) 30 b) -30 c) 20 d) -20 e) -6

D: -20

How many times is the body of the loop below executed? int counter; counter = 1; while (counter > 20) { // body of loop counter = counter + 1; } a) 19 b) 20 c) 21 d) 0 e) syntax error

D: 0

Which of the following segments will call the method readData()four times? // Loop 1 int i; i = 0; while (i != 5) { readData(); i = i + 1; } // Loop 2 int i; i = 0; while (i <= 4) { readData(); i = i + 1; } // Loop 3 int i; i = 0; while ( i < 4 ) { readData(); } // Loop 4 int i; i = 0; while ( i < 4 ) { readData(); i = i + 1; } a) Loop 1 b) Loop 2 c) Loop 3 d) Loop 4 e) none of the above

D: Loop 4

Which of the following reserved words will skip the remainder of the code in an iteration of a loop and then attempt the next iteration? a. static b. break c. private d. continue e. final

D: continue

________ is invoked to create an object. a) The main method b) A method with a return type c) A method with the void return type d) A public variable e) A constructor

E: A constructor

What is the value of isIt after the following code is executed? boolean isIt = 4 + 3 > 6 && 2 + 3 == 1 + 4 && !(1 < 2); a) bananas b) 12 c) 10 d) true e) false

E: False

A method with void return type will always return what variable type? a. String b. int c. double d. Scanner e. None of the above

E: None of the above

What is the value of answer after the following statements? double x = 4; int i = 5; int answer = (x/i) * 2; a) 0 b) 1 c) 1.6 d) 2 e) none of the above (will not compile)

E: None of the above (Will not compile)

Which of the following is not a wrapperclass? a. Boolean b. Double c. Integer d. Byte e. String

E: String

In Java, the following identifiers are all considered to be the same since they have the same spelling. Current current CURRENT a) True b) False

False

True/False: ++is a valid escape sequence.

False

True/False: myNum is a parameter of the example method.

False

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } The scope of the variable radius is limited to the constructor. True or false

False

What is the output after the following code is executed? int i = 1; if(i > 1) { System.out.print("True"); } else { System.out.print("False"); } System.out.println("-End"); False-End True-End -End False True

False-End

Once an object is no longer referenced by any variables, it becomes __________.

Garbage

When a class called HelloWorld.java is compiled successfully, what is the name of the file that is created? HelloWorld.java HelloWorld.class

HelloWorld.class

The Java compiler processes ______________ to create _____________________. Java bytecode, Java source code Java bytecode, machine code Machine code, Java source code Java source code, Java bytecode Java source code, machine code

Java source code, Java bytecode

Refer to the following code (repeated from the previous question) for this question: String moon = "Europa"; String planet = "Jupiter"; String join = " and "; String phrase = (moon.concat(join)).concat(planet); What is the value of newStr after the following line of code is executed? String newStr = planet.replace('E', '!'); Jupit!r !uropa and Jupiter none of the above

Jupiter

When a __________ error occurs, the program's execution ends normally but has incorrect results.

Logical

Which of these are object (or reference) types? Choose all that apply. int double Scanner char String

Scanner String

What belongs in blank __49__?

String

Which of the following is a compile time error? Crash Syntax error (e.g., the semicolon was omitted at the end of the print statement) None of the above All of the above Printing "War Eagle" when the program was supposed to print "The Eagle has Landed"

Syntax error (e.g., the semicolon was omitted at the end of the print statement)

Which of the following will print "War Eagle!" in Java? Put ("War Eagle!"); System.out.println("War Eagle!"); print "War Eagle!"; printf ("War Eagle!"); None of the above

System.out.println("War Eagle!");

Flow of control

The order of statement execution in a method is called the

Autoboxing is the automatic conversion of a primitive value to a corresponding wrapper object. True False

True

Java is a high-level language. True False

True

True/False: jGRASP is an integrated development environment (IDE).

True

What two pieces of information are needed to declare a local variable?

Type and variable name

Sequence

Unless specified otherwise, the order of statement execution in a method is sequential; i.e., one statement after another

The Scanner class separates elements of input into tokens, which are separated by delimiters. What is the default delimiter set? Forward and back slashes ('\' and '/') Punctuation marks ('.', '!', and '?') Semicolons and colons (';' and ':') White space (spaces, tabs, returns, and new line characters) All of the above

White space (spaces, tabs, returns, and new line characters)

The line of Java code: // System.out.println("Hello"); a. will do nothing b. will cause "Hello" to be output c. will cause a syntax error d. will cause "(Hello)" to be output e. there is no way to know without executingthis line of code

Will do nothing

String shape1 = "Circle"; String shape2 = "Square"; Sting shape3 = "Triangle"; string q4 = shape1.indexOf("i") == 2 || shape3.contains ("i") ? "Yes" : "No"; string q5 = shape2.substring(5).equals.("e") && shape2.indexOf ("q") == 1 ? "Yes" : "No"; What is the value of q4? Yes No

Yes

Which of the following is an escape sequence? " int 0 // \n

\n

A(n) ___________ may include a sequence, selection, and iteration of instructions. data algorithm variable None of the above error

algorithm

Given the following, what is the result of running the following program? class Bool { public static void main(String [] args) { boolean b1 = true; boolean b2 = false; boolean b3 = true; if ( b1 && b2 || b2 && b3 || b2 ) System.out.print("Auburn "); if ( b1 && b2 || b2 && b3 || b2 || b1 ) System.out.println("Tigers"); } } a) Auburn b) Tigers c) Auburn Tigers d) No output is produced e) Compilation error

b) Tigers

Which of the following segments will call the method readData()four times? // Loop 1 int i; i = 0; while (i != 5) { readData(); i = i + 1; } // Loop 2 int i; i = 0; while (i <= 4) { readData(); i = i + 1; } // Loop 3 int i; i = 0; while ( i < 4 ) { readData(); } // Loop 4 int i; i = 0; while ( i < 4 ) { readData(); i = i + 1; } a) Loop 1 b) Loop 2 c) Loop 3 d) Loop 4 e) none of the above

d) Loop 4 Explanation: In Loop 1, the loop body will execute for i equal to 0, 1, 2, 3, and 4, which is five times. In Loop 2, the loop body will execute for i equal to 0, 1, 2, 3, and 4, which is five times. In Loop 3, the loop body will execute for an "infinite" number of times, since i is not incremented. In Loop 4, the loop body will execute for i equal to 0, 1, 2, and 3, which is four times.

The order in which a program's instructions execute can be determined by which of the following categories of control constructs a) sequence b) selection c) iteration d) all of the above e) none of the above

d) all of the above

This loop should print: 1 3 5 7 9 for (__12__; __13__; __14__) { System.out.print(i + " "); } What belongs in blank __14__?

i +=2

This loop should print: 1 3 5 7 9 for (__12__; __13__; __14__) { System.out.print(i + " "); } What belongs in blank __13__?

i < 10

What belongs in blank __48__?

i++

What belongs in blank __55__?

index

What belongs in blank __56__?

index--

Creating an object is called ________________. encapsulation instantiation declaration notification proclamation

instantiation

Which of the following is a valid variable type? 0 false int "type" None of the above

int

This loop should print: 1 3 5 7 9 for (__12__; __13__; __14__) { System.out.print(i + " "); } What belongs in blank __12__?

int i = 1

What belongs in blank __47__?

mascots.size())

myNum = myNum - 1; is equivalent to which of the following? myNum *= myNum; myNum--; myNum % myNum; myNum - 1 = myNum; None of the above

myNum--;

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } Which of the following are access modifiers used in the Circle class? (choose all that apply) radiusIn private Math.PI Circle none of the above

private

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } Which of the following are considered instance data? (choose all that apply) radiusIn setRadius(double radiusIn) toString() radius none of the above

radius

Assuming scan is a Scanner object, what does each of the following method calls do? scan.next()

reads the next token as a String

What belongs in blank __57__?

reverse

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } Which of the following are mutator methods? (choose all that apply) radiusIn setRadius(double radiusIn) getRadius() radius none of the above

setRadius(double radiusIn)

Selection

statements that allow us to decide whether or not to execute a particular statement (or block of statements); i.e., select among alternatives Examples: if, if-else, switch statements

Which two modifiers (reserved words) are needed to create a constant?

static and final

A valid value for a variable of type boolean is _________.

true

Which of the following is a valid value for a boolean? "t" "false" 'y' 0 true

true

What belongs in blank __53__?

wellDone.length() -1

Boolean expressions

which evaluate to true or false - are used by Selection and Iteration statements (except switch and for each) to determine whether a statement (or block of statements) is executed

x += y is equivalent to _________.

x = x + y

Refer to the following code for this question: String moon = "Europa"; String planet = "Jupiter"; String join = " and "; String phrase = (moon.concat(join)).concat(planet); What is the value of myChar after the following line of code is executed? char myChar = moon.charAt(3); 'r' 'o' 'p' 'E' none of the above

'o'

ArrayList<String> shapes = new ArrayList<String>(); shapes.add("Circle"); shapes.add("Square"); shapes.add("Triangle"); int before = shapes.indexOf("Square"); shapes.remove(1); int allShapes = shapes.size(); int after = shapes.indexOf("Circle"); In the code above, what is the value of after? Assume all proper imports have been made.

0

What belongs in blank __46__?

0

What belongs in blank __54__?

0

What value is returned when example(1, 2, 3)is called?

0

What value is returned when example(7, 2, 3)is called?

0

public int compare() { String firstShape = "Circle"; String secondShape = "Square"; return firstShape.compareTo(secondShape); } In the code above, does the method compare() return?

0

public void example(int x, int y) { while (x < 5) { if (x == y || x == 1) { } else if (x == y && y == 1) { y += x; } else { y--; } x++; } System.out.printLn(x + "--" + y); } In the code above (repeated from the previous question), how many times will the body of the while loop be executed when example(5, 5) is called?

0

Math.random() will return a double in the range _________. 0 to 99 All positive numbers All real numbers 0 to 1 (excluding 1) None of the above

0 to 1 (excluding 1)

What is printed to standard output based on the following lines of code? double x = 8.765555; DecimalFormat form = new DecimalFormat("00.0#"); System.out.print(form.format(x)); 8.76 00.0# 8.765555 08.77 none of the above

08.77

After the following lines of code are executed, what is the value of myIndex? String myStr = "Exam 1"; int myIndex = myStr.indexOf("x");

1

ArrayList<String> shapes = new ArrayList<String>(); shapes.add("Circle"); shapes.add("Square"); shapes.add("Triangle"); int before = shapes.indexOf("Square"); shapes.remove(1); int allShapes = shapes.size(); int after = shapes.indexOf("Circle"); In the code above, what is the value of before? Assume all proper imports have been made.

1

What is the value of total after the following code is executed? int total = 0; int numberIn = 7; switch (numberIn) { case 3: total += 1; case 7: total += 2; case 9: total += 4; case 11: total += 5; break; default: total += 10; } System.out.println(total);

11

What is the output after the following code is executed? System.out.println(1 + 1); 2 "1 + 1" 1 + 1 (1 + 1) Nothing

2

int = 0; for (int i = 0; i < 3; i ++) { switch x { case 0: x ++; break; case 1: x = x * 2; break; default; x != i; } } System.out.println (x); How many times is the variable i checked? (Note that the code in the image is the same as the previous question) 0 1 2 3 4

4

public void example(int x, int y) { while (x < 5) { if (x == y || x == 1) { } else if (x == y && y == 1) { y += x; } else { y--; } x++; } System.out.printLn(x + "--" + y); } In the code above, how many times will the body of the while loop be executed when example(0, 5) is called?

5

What is the value of myNum after the following code is executed? int myNum = 9 - 4 / 2; 2.5 2 7 0 None of the above

7

int i = 0; x = 0; y = 0; do { switch (y) { case 1: y ++; case 2: x ++; default; x += 2; y ++; } i++; } while (i < 3); What is the value of x after the loop terminates? (Note that the code in the image is the same as the previous question) 3 4 6 7 None of the above

7

What value will z have if we execute the following assignment statement? double z = 5 / 10; a) 0.0 b) 0.5 c) 5.0 d) 0.05 e) none of the above

A: 0.0

Mistyping "println" inSystem.out.printn("Test");will result in a) a compile-time error b) a run-time error c) a logical error d) no error at all e) converting the statement into a comment

A: compile-time error

Which of the following lines of code properly converts the String "98.6"toadouble? a. double x = Double.parseDouble("98.6"); b. double x = String.toDouble("98.6"); c. double x = String.toFloat("98.6"); d. double x = Double.parse("98.6"); e. None of the above

A: double x = Double.parseDouble("98.6");

A programmer is supposed to write a program with the expected output "Hello World". During testing, the actual output of the program is found to be "Hello". What type of error has occurred? a) a compile-time error b) a run-time error c) a logical error d) no error at all e) converting the statement into a comment

A: logical error

What belongs in blank __16__?

A: void

True/False: // is used for a multiline comment.

B: False

If a method does not have a return statement, then a) it will produce a syntax error when compiled b) it must have a void return type c) it cannot be called from outside the class that defined the method d) it must be defined to be a public method e) it must be an int, double, float or String method

B: It must have a void return type

Well-encapsulated classes have _______________ instance variables and ________________ service methods. a) public, private b) private, public c) formal, actual d) actual formal e) none of the above

B: Private, Public

Suppose that myObj is an instance of the class that contains the methods turnRight and turnLeft. Which method will be invoked on myObj if inValue is equal to 'U'? What is the return type for methods turnRight and turnLeft?

Boolean

Which of the following is nota valid primitive type? a.boolean b.int c.String d.double e.char

C: String

The order in which a program's instructions execute can be determined by which of the following categories of control constructs a) sequence b) selection c) iteration d) all of the above e) none of the above

D: All of the above

What belongs in blank __14__?

D: double

Which one of the modifiers below is used to indicate that an instance variable is directly accessible only inside the class where it is defined (e.g., the instance variable cannot be assigned a value outside of its class)? a. public b. final c. protected d. private e. static

D: private

If found is a variable declared to be of type boolean, which of the following values can be assigned to found? a) 0 and 1 b) T and F c) True and False d) true and false e) C and D f) All of the above

D: true and false

Which of the following would return the last character of the String x? a) x.charAt(0); b) x.charAt(end); c) x.charAt(length(x)); d) x.charAt(x.length()-1); e) x. last();

D: x.CharAt(x.length()-1);

If you want to assign String name the value "US President", which statement will work? a) String name = "US President"; b) String name = new String("US President"); c) String name = "US" + " " + "President"; d) String name = new String("US" + " " + "President"); e) Any of the above would work

E: Any of the above would work

Which of the following is an access modifier? a.// b.== c.String d.int e.public

E: public

What belongs in blank __15__?

E: weightIn

Refer to the following code (repeated from the previous question) for this question: String moon = "Europa"; String planet = "Jupiter"; String join = " and "; String phrase = (moon.concat(join)).concat(planet); What is the value of the String phrase? Europa and Jupiter Europa Jupiter and Europa Jupiter none of the above

Europa and Jupiter

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } Which one of the following is a constant? radiusIn radius Math.PI Circle none of the above

Math.PI

The word println in System.out.println() is a ________.

Method

Assuming scan is a Scanner object, what does each of the following method calls do? scan.nextLine()

Reads the next line as String

Assuming scan is a Scanner object, what does each of the following method calls do? scan.nextDouble()

Reads the next token as a double

Assuming scan is a Scanner object, what does each of the following method calls do? scan.nextInt()

Reads the next token as an int

In the context of programs, the language semantics describes what will happen when a legal statement in the language is executed. True or False

True

Reference variables which are aliases point to the same object in memory. True False

True

The statements x++; and ++x; will accomplish the same thing but the statements y = x++; and y = ++x; will not. a) True b) False

True

True/False: A UML class diagram shows the dependencies among the classes in the diagram.

True

True/False: An instance variable has scope of the entire class

True

True/False: The semantics of a language define the meaning of a statement in the language.

True

True/False: When using the assignment operator, the expression on the right side is evaluated before being stored in the variable on the left side.

True

String shape1 = "Circle"; String shape2 = "Square"; Sting shape3 = "Triangle"; string q4 = shape1.indexOf("i") == 2 || shape3.contains ("i") ? "Yes" : "No"; string q5 = shape2.substring(5).equals.("e") && shape2.indexOf ("q") == 1 ? "Yes" : "No"; What is the value of q5? (Note that the code in the image is the same as the previous question) Yes No

Yes

The ______ statement will skip the remainder of the code in the loop and exit the loop.

break

The new operator calls the ____________ of class to create an instance or object of the class. object public constructor null int

constructor

The ______ statement will skip the remainder of the code in the loop and attempt the next iteration of the loop.

continue

How many times is the body of the loop below executed? int counter; counter = 1; while (counter > 20) { // body of loop counter = counter + 1; } a) 19 b) 20 c) 21 d) 0 e) syntax error

d) 0

What is the value of isIt after the following code is executed? boolean isIt = 4 + 3 > 6 && 2 + 3 == 1 + 4 && !(1 < 2); a) bananas b) 12 c) 10 d) true e) false

e) false

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } Which of the following are accessor methods? (choose all that apply) radiusIn setRadius(double radiusIn) getRadius() radius none of the above

getRadius()

Suppose you have an instance of the Random class called gen. Which of the following lines of code generates a random integer in the range 10 to 40 (inclusive) and assigns it to myNum?

int myNum = gen.nextInt(31) + 10;

Suppose that myObj is an instance of the class that contains the methods turnRight and turnLeft. Which method will be invoked on myObj if inValue is equal to 'U'? boolean result = (inValue == 'R') ? myObj.turnRight() : myObj.turnLeft();

myObj.turnLeft()

What belongs in blank __50__?

name

Which operator is used to call a constructor?

new

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } Which of the following are Constructors? (choose all that apply) radiusIn setRadius(double radiusIn) toString() radius none of the above

none of the above

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } Which of the following violate encapsulation? (choose all that apply) radiusIn setRadius(double radiusIn) toString() radius none of the above

none of the above

public class Circle { private double radius; public Circle(double radiusIn) { radius = radiusIn; } public double getRadius() { return radius; } public void setRadius(double radiusIn) { radius = radiusIn; } public double area() { return Math.PI * Math.pow(radius, 2); } public String toString() { return "The circle has radius " + radius + " and area " + area(); } } What is the return type of the setRadius() method? void radiusIn radius String none of the above

void

Assuming that x, y, and z are of type double, which of the following lines of code matches the equation? 𝒙=𝟐𝒚𝟓+|𝒛|𝟐

x = 2 * Math.pow(y, 5) + Math.abs(z), 2);


Set pelajaran terkait

DA211-Ch.23 Chemical and Waste Management

View Set

D216 Business Law For Accountants

View Set

Legal Rights/Responsibilities & Ethical Issues Practice Questions :)

View Set

world history AGE OF ENLIGHTENMENT

View Set

Introduction to Research Essentials

View Set

3 most influential economists (Essay Question 1)

View Set

Chapter 56 Caring for Clients with sexually transmitted infections

View Set