Ummm No
Quiz von , erstellt am more than 1 year ago

A practice test for Gwinnett Tech's Level 1 java class

1474
19
0
Ummm No
Erstellt von Ummm No vor fast 9 Jahre
Schließen

Java Practice 1

Frage 1 von 200

1

________is a technical definition of the language that includes the syntax and semantics of the Java programming language.

Wähle eine der folgenden:

  • Java JDK

  • Java language specification

  • Java IDE

  • Java API

Erklärung

Frage 2 von 200

1

Which JDK command is correct to run a Java application in ByteCode.class?

Wähle eine der folgenden:

  • java ByteCode.class

  • javac ByteCode.java

  • javac ByteCode

  • JAVAC ByteCode

  • java ByteCode

Erklärung

Frage 3 von 200

1

________ is a software that interprets Java bytecode.

Wähle eine der folgenden:

  • Java virtual machine

  • Java API

  • Java compiler

  • Java debugger

Erklärung

Frage 4 von 200

1

________ is an operating system.

Wähle eine der folgenden:

  • Visual Basic

  • Ada

  • C++

  • Windows XP

  • Java

Erklärung

Frage 5 von 200

1

Which of the following are the reserved words? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • void

  • class

  • static

  • public

Erklärung

Frage 6 von 200

1

________is interpreted.

Wähle eine der folgenden:

  • Ada

  • Pascal

  • Java

  • C++

  • C

Erklärung

Frage 7 von 200

1

________ contains predefined classes and interfaces for developing Java programs.

Wähle eine der folgenden:

  • Java JDK

  • Java API

  • Java language specification

  • Java IDE

Erklärung

Frage 8 von 200

1

Which of the following statements is correct?

Wähle eine der folgenden:

  • Every line in a program must end with a semicolon.

  • Every comment line must end with a semicolon.

  • Every method must end with a semicolon.

  • Every class must end with a semicolon.

  • Every statement in a program must end with a semicolon.

Erklärung

Frage 9 von 200

1

________provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.

Wähle eine der folgenden:

  • Java JDK

  • Java language specification

  • Java API

  • Java IDE

Erklärung

Frage 10 von 200

1

Java was developed by ________.

Wähle eine der folgenden:

  • Cisco Systems

  • Sun Microsystems

  • Oracle

  • Microsoft

  • IBM

Erklärung

Frage 11 von 200

1

Java compiler translates Java source code into ________.

Wähle eine der folgenden:

  • assembly code

  • another high-level language code

  • Java bytecode

  • machine code

Erklärung

Frage 12 von 200

1

Suppose you define a Java class as follows:

public class Test {

}

In order to compile this program, the source code should be stored in a file named

Wähle eine der folgenden:

  • Test.class

  • Any name with extension .java

  • Test.java

  • Test.doc

  • Test.txt

Erklärung

Frage 13 von 200

1

________is Architecture-Neutral.

Wähle eine der folgenden:

  • C++

  • Pascal

  • Java

  • Ada

  • C

Erklärung

Frage 14 von 200

1

Java ________ can run from a Web browser.

Wähle eine der folgenden:

  • servlets

  • Micro Edition programs

  • applets

  • applications

Erklärung

Frage 15 von 200

1

________ is the brain of a computer.

Wähle eine der folgenden:

  • Disk

  • Memory

  • CPU

  • Hardware

Erklärung

Frage 16 von 200

1

The expression "Java " + 1 + 2 + 3 evaluates to ________.

Wähle eine der folgenden:

  • Java123

  • java 123

  • Java 123

  • Java6

  • Illegal expression

Erklärung

Frage 17 von 200

1

If a program compiles fine, but it produces incorrect result, then the program suffers ________.

Wähle eine der folgenden:

  • a compilation error

  • a logic error

  • a runtime error

Erklärung

Frage 18 von 200

1

Which of the following code displays the area of a circle if the radius is positive?

Wähle eine der folgenden:

  • if (radius <= 0) System.out.println(radius * radius * 3.14159);

  • if (radius >= 0) System.out.println(radius * radius * 3.14159);

  • if (radius > 0) System.out.println(radius * radius * 3.14159);

  • if (radius != 0) System.out.println(radius * radius * 3.14159);

Erklärung

Frage 19 von 200

1

What is 1 + 1 + 1 + 1 + 1 == 5?

Wähle eine der folgenden:

  • There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.

  • true

  • false

Erklärung

Frage 20 von 200

1

Suppose x is 1. What is x after x += 2?

Wähle eine der folgenden:

  • 2

  • 3

  • 1

  • 4

  • 0

Erklärung

Frage 21 von 200

1

Which of the following expression results in a value 1?

Wähle eine der folgenden:

  • 2 % 1

  • 25 % 5

  • 15 % 4

  • 37 % 6

Erklärung

Frage 22 von 200

1

Which of the following are correct names for variables according to Java naming conventions? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • FindArea

  • RADIUS

  • Radius

  • findArea

  • radius

Erklärung

Frage 23 von 200

1

What is x after the following statements?

int x = 1;
x *= x + 1;

Wähle eine der folgenden:

  • x is 2.

  • x is 3.

  • x is 1.

  • x is 4.

Erklärung

Frage 24 von 200

1

What is the result of 45 / 4?

Wähle eine der folgenden:

  • 11

  • 11.25

  • 12

  • 10

Erklärung

Frage 25 von 200

1

Analyze the following code:

boolean even = false;
if (even = true) {
System.out.println("It is even!");
}

Wähle eine der folgenden:

  • The program has a compile error.

  • The program runs fine and displays It is even!.

  • The program has a runtime error.

  • The program runs fine, but displays nothing.

Erklärung

Frage 26 von 200

1

What is i printed in the following code?

public class Test {
public static void main(String[ ] args) {
int j = 0;
int i = j++ + j * 5;
System.out.println("What is i? " + i);
}
}

Wähle eine der folgenden:

  • 6

  • 1

  • 5

  • 0

Erklärung

Frage 27 von 200

1

25 % 1 is ________.

Wähle eine der folgenden:

  • 3

  • 1

  • 4

  • 2

  • 0

Erklärung

Frage 28 von 200

1

Analyze the following code. (Choose all that apply.)

int count = 0;
while (count < 100) {
// Point A
System.out.println("Welcome to Java!");
count++;
// Point B
}
// Point C

Wähle eine oder mehr der folgenden:

  • count < 100 is always false at Point C

  • count < 100 is always true at Point A

  • count < 100 is always true at Point C

  • count < 100 is always false at Point B

  • count < 100 is always true at Point B

Erklärung

Frage 29 von 200

1

How many times will the following code print "Welcome to Java"?

int count = 0;
while (count < 10) {
System.out.println("Welcome to Java");
count++;
}

Wähle eine der folgenden:

  • 11

  • 9

  • 0

  • 8

  • 10

Erklärung

Frage 30 von 200

1

Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?

Wähle eine der folgenden:

  • c

  • a

  • d

  • b

Erklärung

Frage 31 von 200

1

Analyze the following code:

Code 1:

boolean even;

if (number % 2 == 0)
even = true;
else
even = false;

Code 2:

boolean even = (number % 2 == 0);

Wähle eine der folgenden:

  • Code 2 has compile errors.

  • Both Code 1 and Code 2 have compile errors.

  • Code 1 has compile errors.

  • Both Code 1 and Code 2 are correct, but Code 2 is better.

Erklärung

Frage 32 von 200

1

Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

Wähle eine der folgenden:

  • 1 < x < 100 && x < 0

  • ((x < 100) && (x > 1)) || (x < 0)

  • ((x < 100) && (x > 1)) && (x < 0)

  • (1 > x > 100) || (x < 0)

Erklärung

Frage 33 von 200

1

Suppose x=10 and y=10 what is x after evaluating the expression (y > 10) && (x++ > 10)?

Wähle eine der folgenden:

  • 9

  • 11

  • 10

Erklärung

Frage 34 von 200

1

What is 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0?

Wähle eine der folgenden:

  • true

  • false

  • There is no guarantee that 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0 is true.

Erklärung

Frage 35 von 200

1

What is the printout of the following switch statement?
char ch = 'a';
switch (ch) {
case 'a':
case 'A':
System.out.print(ch); break;
case 'b':
case 'B':
System.out.print(ch); break;
case 'c':
case 'C':
System.out.print(ch); break;
case 'd':
case 'D':
System.out.print(ch);
}

Wähle eine der folgenden:

  • a

  • aa

  • abcd

  • abc

  • ab

Erklärung

Frage 36 von 200

1

What is y after the following switch statement is executed?

x = 3;
switch (x + 3) {
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}

Wähle eine der folgenden:

  • 3

  • 1

  • 2

  • 4

Erklärung

Frage 37 von 200

1

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

Wähle eine oder mehr der folgenden:

  • (x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 && y < 0))

  • (x > 0 || x < 10) is same as ((x > 0) || (x < 10))

  • (x > 0 || x < 10 && y < 0) is same as ((x > 0 || x < 10) && y < 0)

  • (x > 0 && x < 10) is same as ((x > 0) && (x < 10))

Erklärung

Frage 38 von 200

1

What is the printout of the following switch statement?

char ch = 'b';

switch (ch) {
case 'a':
System.out.print(ch);
case 'b':
System.out.print(ch);
case 'c':
System.out.print(ch);
case 'd':
System.out.print(ch);
}

Wähle eine der folgenden:

  • b

  • bb

  • bcd

  • abcd

  • bbb

Erklärung

Frage 39 von 200

1

Analyze the following program fragment:

int x;
double d = 1.5;

switch (d) {
case 1.0: x = 1;
case 1.5: x = 2;
case 2.0: x = 3;
}

Wähle eine der folgenden:

  • No errors.

  • The program has a compile error because the required break statement is missing in the switch statement.

  • The switch control variable cannot be double.

  • The program has a compile error because the required default case is missing in the switch statement.

Erklärung

Frage 40 von 200

1

Which of the following are valid specifiers for the printf statement? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • %6d

  • %10b

  • %4c

  • %8.2d

  • %10.2e

Erklärung

Frage 41 von 200

1

Analyze the following code.

boolean even = false;
if (even) {
System.out.println("It is even!");
}

Wähle eine der folgenden:

  • The code displays It is even!

  • The code is wrong. You should replace if (even) with if (even = true)

  • The code is wrong. You should replace if (even) with if (even == true)

  • The code displays nothing.

Erklärung

Frage 42 von 200

1

Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?

Wähle eine der folgenden:

  • 10

  • 11

  • 9

Erklärung

Frage 43 von 200

1

The "less than or equal to" comparison operator in Java is ________.

Wähle eine der folgenden:

  • <

  • !=

  • <=

  • =<

  • <<

Erklärung

Frage 44 von 200

1

What is the output of the following code?

char ch = 'F';
if (ch >= 'A' && ch <= 'Z')
System.out.println(ch);

Wähle eine der folgenden:

  • F

  • f

  • nothing

  • F f

Erklärung

Frage 45 von 200

1

________ is the code with natural language mixed with Java code.

Wähle eine der folgenden:

  • Pseudocode

  • A Java statement

  • A flowchart diagram

  • Java program

Erklärung

Frage 46 von 200

1

The statement System.out.printf("%3.1e", 1234.56) outputs ________.

Wähle eine der folgenden:

  • 1.23+03

  • 1.2e+03

  • 0.1e+04

  • 0.123456e+04

  • 0.123e+04

Erklärung

Frage 47 von 200

1

Suppose income is 4001, what is the output of the following code:

if (income > 3000) {
System.out.println("Income is greater than 3000");
}
else if (income > 4000) {
System.out.println("Income is greater than 4000");

Wähle eine der folgenden:

  • Income is greater than 3000 followed by Income is greater than 4000

  • Income is greater than 3000

  • Income is greater than 4000 followed by Income is greater than 3000

  • no output

  • Income is greater than 4000

Erklärung

Frage 48 von 200

1

Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10)?

Wähle eine der folgenden:

  • 11

  • 10

  • 9

Erklärung

Frage 49 von 200

1

Analyze the following code fragments that assign a boolean value to the variable even.

Code 1:
if (number % 2 == 0)
even = true;
else
even = false;

Code 2:
even = (number % 2 == 0) ? true: false;

Code 3:
even = number % 2 == 0;

Wähle eine der folgenden:

  • All three are correct, but Code 1 is preferred.

  • All three are correct, but Code 3 is preferred.

  • Code 3 has a compile error, because you attempt to assign number to even.

  • Code 2 has a compile error, because you cannot have true and false literals in the conditional expression

  • All three are correct, but Code 2 is preferred.

Erklärung

Frage 50 von 200

1

What is the value of the following expression?
true || true && false

Wähle eine der folgenden:

  • true

  • false

Erklärung

Frage 51 von 200

1

Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?

if (x > 0)
if (y > 0)
System.out.println("x > 0 and y > 0");
else if (z > 0)
System.out.println("x < 0 and z > 0");

Wähle eine der folgenden:

  • x < 0 and z < 0;

  • no printout.

  • x > 0 and y > 0;

  • x < 0 and z > 0;

Erklärung

Frage 52 von 200

1

"AbA".compareToIgnoreCase("abC") returns ________.

Wähle eine der folgenden:

  • 1

  • 2

  • -1

  • -2

  • 0

Erklärung

Frage 53 von 200

1

What is the printout of System.out.println('z' - 'a')?

Wähle eine der folgenden:

  • 25

  • 26

  • a

  • z

Erklärung

Frage 54 von 200

1

Assume that the ASCII code for character c is 99 and for a is 97. What is the printout of the following code?

System.out.println('a' + 'c');

Wähle eine der folgenden:

  • a99

  • ac

  • 9799

  • 196

Erklärung

Frage 55 von 200

1

Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.

Wähle eine der folgenden:

  • 66

  • B

  • A1

  • Illegal expression

Erklärung

Frage 56 von 200

1

Which of the following method results in 8.0?

Wähle eine oder mehr der folgenden:

  • Math.round(8.5)

  • Math.rint(8.5)

  • Math.ceil(8.5)

  • Math.floor(8.5)

Erklärung

Frage 57 von 200

1

The expression 'c' - 'e' is ________.

Wähle eine der folgenden:

  • 2

  • -2

  • a random number

  • invalid

Erklärung

Frage 58 von 200

1

Math.ceil(5.5) evaluates to ________.

Wähle eine der folgenden:

  • 5.0

  • 6.0

  • 5

  • 6

Erklärung

Frage 59 von 200

1

Math.floor(5.5) evaluates to ________.

Wähle eine der folgenden:

  • 5.0

  • 6.0

  • 5

  • 6

Erklärung

Frage 60 von 200

1

To obtain the sine of 35 degrees, use ________.

Wähle eine der folgenden:

  • Math.sin(35)

  • Math.sin(Math.toRadians(35))

  • Math.sin(Math.toDegrees(35))

  • Math.sin(Math.toRadian(35))

  • Math.sin(Math.toDegree(35))

Erklärung

Frage 61 von 200

1

Which of the following is the correct expression of character a?

Wähle eine der folgenden:

  • 'a'

  • "a"

  • '\000a'

  • '\a'

Erklärung

Frage 62 von 200

1

Math.cos(Math.PI) returns ________.

Wähle eine der folgenden:

  • 0.0

  • 1.0

  • -1.0

  • 0.5

Erklärung

Frage 63 von 200

1

Which of the following assignment statements is correct?

Wähle eine oder mehr der folgenden:

  • char c = 'd';

  • char c = 100;

  • char c = "d";

  • char c = "100";

Erklärung

Frage 64 von 200

1

What is i after the following for loop?

int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}

Wähle eine der folgenden:

  • 9

  • undefined

  • 10

  • 11

Erklärung

Frage 65 von 200

1

Which of the following will not help prevent infinite loops?

Wähle eine der folgenden:

  • Ensure that the header of a for or while statement is not followed by a semicolon.

  • If the loop is counter-controlled, the body of the loop should increment or decrement the counter as needed.

  • If the loop is sentinel-controlled, ensure that the sentinel value is input eventually.

  • Include braces around the statements in a do..while statement.

Erklärung

Frage 66 von 200

1

How many times will the following code print "Welcome to Java"?

int count = 0;
do {
System.out.println("Welcome to Java");
} while (++count < 10);

Wähle eine der folgenden:

  • 9

  • 10

  • 0

  • 11

  • 8

Erklärung

Frage 67 von 200

1

For the code segment below:

switch( q )
{
case 1:
System.out.println( "apple" );
break;
case 2:
System.out.println( "orange" );
break;
case 3:
System.out.println( "banana" );
break;
case 4:
System.out.println( "pear" );
case 5:
System.out.println( "grapes" );
default:
System.out.println( "kiwi" );
} // end switch

Which of the following values for q will result in kiwi being included in the output?

Wähle eine der folgenden:

  • 2

  • 3

  • Anything greater than or equal to 4.

  • 1

Erklärung

Frage 68 von 200

1

Which of the following for-loop control headers results in equivalent numbers of iterations:

A. for ( int q = 1; q <= 100; q++ )
B. for ( int q = 100; q >= 0; q-- )
C. for ( int q = 99; q > 0; q -= 9 )
D. for ( int q = 990; q > 0; q -= 90 )

Wähle eine der folgenden:

  • C and D.

  • A and B.

  • None of the loops have equivalent iterations.

  • A and B have equivalent iterations and C and D have equivalent iterations.

Erklärung

Frage 69 von 200

1

To exit out of a loop completely, and resume the flow of control at the next line in the method, use _______.

Wähle eine der folgenden:

  • A continue statement.

  • A break statement.

  • A return statement.

  • Any of the above.

Erklärung

Frage 70 von 200

1

What is the value in count after the following loop is executed?

int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 9);
System.out.println(count);

Wähle eine der folgenden:

  • 0

  • 8

  • 9

  • 11

  • 10

Erklärung

Frage 71 von 200

1

What is sum after the following loop terminates?

int sum = 0;
int item = 0;
do {
item++;
sum += item;
if (sum >= 4) continue;
}
while (item < 5);

Wähle eine der folgenden:

  • 15

  • 18

  • 17

  • 16

Erklärung

Frage 72 von 200

1

What is the output for y?

int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}
System.out.println(y);

Wähle eine der folgenden:

  • 11

  • 13

  • 45

  • 10

  • 12

Erklärung

Frage 73 von 200

1

Which of the following is not a type of repetition statement in Java?

Wähle eine der folgenden:

  • do¦while statements.

  • for statements.

  • while statements.

  • loop statements.

Erklärung

Frage 74 von 200

1

Which of the following statements about the continue statement is true?

Wähle eine der folgenden:

  • The continue statement is used to continue after a switch statement.

  • The continue statement is used to exit a repetition structure early and continue execution after the loop.

  • The continue statement does not alter the flow of control.

  • A continue statement proceeds with the next iteration of the immediately enclosing while, for, do¦while statement.

Erklärung

Frage 75 von 200

1

Suppose the input for number is 9. What is the output from running the following program?

import java.util.Scanner;

public class Test {
public static void main(String[ ] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();

int i;

boolean isPrime = true;
for (i = 2; i < number && isPrime; i++) {
if (number % i == 0) {
isPrime = false;
}
}

System.out.println("i is " + i);

if (isPrime)
System.out.println(number + " is prime");
else
System.out.println(number + " is not prime");
}
}

Wähle eine der folgenden:

  • i is 4 followed by 9 is prime

  • i is 3 followed by 9 is not prime

  • i is 3 followed by 9 is prime

  • i is 4 followed by 9 is not prime

Erklärung

Frage 76 von 200

1

Analyze the following code: (Choose all that apply.)

public class Test {
public static void main (String args[ ]) {
int i = 0;
for (i = 0; i < 10; i++);
System.out.println(i + 4);
}
}

Wähle eine oder mehr der folgenden:

  • The program has a compile error because of the semicolon (;) on the for loop line.

  • The for loop in this program is same as for (i = 0; i < 10; i++) { }; System.out.println(i + 4);

  • The program compiles despite the semicolon (;) on the for loop line, and displays 14.

  • The program compiles despite the semicolon (;) on the for loop line, and displays 4.

Erklärung

Frage 77 von 200

1

The parameter list in the method header and the arguments in the method call must agree in:

Wähle eine der folgenden:

  • type

  • number

  • order

  • all the above

Erklärung

Frage 78 von 200

1

What is Math.rint(3.5)?

Wähle eine der folgenden:

  • 5.0

  • 4.0

  • 3.0

  • 3

  • 4

Erklärung

Frage 79 von 200

1

Which is a correct static method call of Math class method sqrt?

Wähle eine der folgenden:

  • Math.sqrt( 900 );.

  • sqrt( 900 );.

  • math.sqrt( 900 );.

  • Math math = new Math(); math.sqrt( 900 );.

Erklärung

Frage 80 von 200

1

You can set a Random object's seed at any time during program execution by calling the object's ________ methods.

Wähle eine der folgenden:

  • updateSeed.

  • setSeed

  • changeSeed.

  • resetSeed.

Erklärung

Frage 81 von 200

1

Identifiers in Java have ________ and ________ scopes?

Wähle eine der folgenden:

  • statement, file.

  • class, block.

  • method, class.

  • block, statement.

Erklärung

Frage 82 von 200

1

A well-designed method

Wähle eine der folgenden:

  • contains thousands of lines of code.

  • performs multiple unrelated tasks.

  • repeats code found in other methods.

  • performs a single, well-defined task.

Erklärung

Frage 83 von 200

1

Which of the following methods is not in the Math class?

Wähle eine der folgenden:

  • parseInt.

  • abs.

  • ceil.

  • log.

Erklärung

Frage 84 von 200

1

Which statement below could be used to simulate the outputs of rolling a six-sided die? Suppose randomNumbers is a Random object.

Wähle eine der folgenden:

  • 1 + randomNumbers.nextInt( 2 );

  • 6 + randomNumbers.nextInt( 1 );

  • 3 + randomNumbers.nextInt( 3 );

  • 1 + randomNumbers.nextInt( 6 );

Erklärung

Frage 85 von 200

1

Which of the following can be an argument to a method?

Wähle eine der folgenden:

  • Constants.

  • Variables.

  • Expressions.

  • All of the above.

Erklärung

Frage 86 von 200

1

To declare a method as static, place the keyword static before ________ in the method's declaration

Wähle eine der folgenden:

  • the return type.

  • the method name.

  • the argument list.

  • the method modifier.

Erklärung

Frage 87 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
System.out.println(xMethod(5, 500L));
}

public static int xMethod(int n, long l) {
System.out.println("int, long");
return n;
}

public static long xMethod(long n, long l) {
System.out.println("long, long");
return n;
}
}

Wähle eine der folgenden:

  • The program displays int, long followed by 5.

  • The program displays long, long followed by 5.

  • The program runs fine but displays things other than 5.

  • The program does not compile because the compiler cannot distinguish which xmethod to invoke.

Erklärung

Frage 88 von 200

1

Declaring main as ________ allows the JVM to invoke main without creating an instance of the class.

Wähle eine der folgenden:

  • void.

  • public.

  • final.

  • static.

Erklärung

Frage 89 von 200

1

Variables should be declared as fields only if

Wähle eine der folgenden:

  • they are used only within a method.

  • they are local variables.

  • they are required for use in more than one method or their values must be saved between calls to the class's methods.

  • they are arguments.

Erklärung

Frage 90 von 200

1

Which of the following methods are overloaded with respect to one another?

A. public int max ( int a, int b ) { … }
B. public double max ( double a, double b ) { … }
C. public int max ( int a, int b, int c ) { … }
D. public double max ( double a, double b, double c ) { … }

Wähle eine der folgenden:

  • A and B are overloaded; C and D are overloaded.

  • A and C are overloaded; B and D are overloaded.

  • All these four methods are overloaded.

  • A, B and C are overloaded.

Erklärung

Frage 91 von 200

1

The identifiers in an enumeration ________.

Wähle eine der folgenden:

  • must be lowercase letters and cannot contain numbers.

  • must be unique.

  • must be uppercase letters and cannot contain numbers.

  • may be duplicated.

Erklärung

Frage 92 von 200

1

Analyze the following code.

public class Test {
public static void main(String[ ] args) {
System.out.println(max(1, 2));
}

public static double max(int num1, double num2) {
System.out.println("max(int, double) is invoked");

if (num1 > num2)
return num1;
else
return num2;
}

public static double max(double num1, int num2) {
System.out.println("max(double, int) is invoked");

if (num1 > num2)
return num1;
else
return num2;
}
}

Wähle eine der folgenden:

  • The program cannot compile because the compiler cannot determine which max method should be invoked.

  • The program runs and prints 2 followed by "max(int, double)" is invoked.

  • The program cannot compile because you cannot have the print statement in a non-void method.

  • The program runs and prints "max(int, double) is invoked" followed by 2.

  • The program runs and prints 2 followed by "max(double, int)" is invoked.

Erklärung

Frage 93 von 200

1

What is Math.floor(3.6)?

Wähle eine der folgenden:

  • 3.0

  • 5.0

  • 4

  • 3

Erklärung

Frage 94 von 200

1

What is Math.round(3.6)?

Wähle eine der folgenden:

  • 3.0

  • 3

  • 4

  • 4.0

Erklärung

Frage 95 von 200

1

(int)('a' + Math.random() * ('z' - 'a' + 1)) returns a random number ________.

Wähle eine der folgenden:

  • between 'a' and 'z'

  • between (int)'a' and (int)'z'

  • between 0 and (int)'z'

  • between 'a' and 'y'

Erklärung

Frage 96 von 200

1

Given the following method

static void nPrint(String message, int n) {
while (n > 0) {
System.out.print(message);
n--;
}
}

What is k after invoking nPrint("A message", k)?

int k = 2;
nPrint("A message", k);

Wähle eine der folgenden:

  • 3

  • 0

  • 1

  • 2

Erklärung

Frage 97 von 200

1

Does the method call in the following method cause compile errors?

public static void main(String[ ] args) {
Math.pow(2, 4);
}

Wähle eine der folgenden:

  • Yes

  • No

Erklärung

Frage 98 von 200

1

Method calls cannot be distinguished by ________.

Wähle eine der folgenden:

  • return type.

  • method name.

  • method signature.`

  • parameter lists.

Erklärung

Frage 99 von 200

1

________ is to implement one method in the structure chart at a time from the top to the bottom.

Wähle eine der folgenden:

  • Bottom-up approach

  • Stepwise refinement

  • Bottom-up and top-down approach

  • Top-down approach

Erklärung

Frage 100 von 200

1

Which of the following is a possible output from invoking Math.random()? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • 3.43

  • 0.0

  • 1.0

  • 0.5

Erklärung

Frage 101 von 200

1

Which statement below could be used to simulate the outputs of tossing a quarter to get heads or tails? Suppose randomNumbers is a Random object.

Wähle eine der folgenden:

  • randomNumbers.nextInt( 7 );

  • randomNumbers.nextInt( 1 );

  • randomNumbers.nextInt( 2 );

  • randomNumbers.nextInt( 25 );

Erklärung

Frage 102 von 200

1

A Java class can have which of the following methods?

A. void foo( int a )
B. void foo( int a, int b )
C. void foo( double a )
D. void foo( double a, double b )
E. void foo( int b )

Wähle eine der folgenden:

  • A, B, C, D.

  • All of the above.

  • A, C, D, E.

  • A, B, D, E.

Erklärung

Frage 103 von 200

1

If more method calls occur than can have their activation records stored on the program execution stack, an error known as a ________ occurs.

Wähle eine der folgenden:

  • stack empty.

  • stack overflow.

  • stack full.

  • stack rewind.

Erklärung

Frage 104 von 200

1

Which statement creates a random value from the sequence 2, 5, 8, 11 and 14. Suppose randomNumbers is a Random object.

Wähle eine der folgenden:

  • 3 + 2 * randomNumbers.nextInt( 5 );

  • 5 + 3 * randomNumbers.nextInt( 2 );

  • 2 + 3 * randomNumbers.nextInt( 5 );

  • 2 + 5 * randomNumbers.nextInt( 3 );

Erklärung

Frage 105 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
final int[ ] x = {1, 2, 3, 4};
int[ ] y = x;

x = new int[2];

for (int i = 0; i < y.length; i++)
System.out.print(y[i] + " ");
}
}

Wähle eine der folgenden:

  • The program displays 0 0

  • The program displays 1 2 3 4

  • The program has a compile error on the statement x = new int[2], because x is final and cannot be changed.

  • The elements in the array x cannot be changed, because x is final.

Erklärung

Frage 106 von 200

1

For the binarySearch method in Section 6.9.2, what is low and high after the first iteration of the while loop when invoking binarySearch(new int[ ]{1, 4, 6, 8, 10, 15, 20}, 11)?

Wähle eine der folgenden:

  • low is 3 and high is 6

  • low is 0 and high is 5

  • low is 4 and high is 6

  • low is 0 and high is 6

  • low is 0 and high is 3

Erklärung

Frage 107 von 200

1

Analyze the following code.

public class Test {
public static void main(String[ ] args) {
int[ ] x = new int[3];
System.out.println("x[0] is " + x[0]);
}
}

Wähle eine der folgenden:

  • The program has a runtime error because the array element x[0] is not defined.

  • The program runs fine and displays x[0] is 0.

  • The program has a compile error because the size of the array wasn't specified when declaring the array.

  • The program has a runtime error because the array elements are not initialized.

Erklärung

Frage 108 von 200

1

Assume int[ ] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 30) return?

Wähle eine der folgenden:

  • 1

  • -1

  • 2

  • -2

  • 0

Erklärung

Frage 109 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
int[ ] x = new int[5];
int i;
for (i = 0; i < x.length; i++)
x[i] = i;
System.out.println(x[i]);
}
}

Wähle eine der folgenden:

  • The program has a compile error because i is not defined in the last statement in the main method.

  • The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException.

  • The program displays 4.

  • The program displays 0 1 2 3 4.

Erklärung

Frage 110 von 200

1

The reverse method is defined in the textbook. What is list1 after executing the following statements?

int[ ] list1 = {1, 2, 3, 4, 5, 6};
list1 = reverse(list1);

Wähle eine der folgenden:

  • list1 is 6 5 4 3 2 1

  • list1 is 0 0 0 0 0 0

  • list1 is 1 2 3 4 5 6

  • list1 is 6 6 6 6 6 6

Erklärung

Frage 111 von 200

1

What would be the result of attempting to compile and run the following code?

public class Test {
public static void main(String[ ] args) {
double[ ] x = new double[ ]{1, 2, 3};
System.out.println("Value is " + x[1]);
}
}

Wähle eine der folgenden:

  • The program has a compile error because the syntax new double[ ]{1, 2, 3} is wrong and it should be replaced by new double[ ]{1.0, 2.0, 3.0};

  • The program compiles and runs fine and the output "Value is 1.0" is printed.

  • The program compiles and runs fine and the output "Value is 2.0" is printed.

  • The program has a compile error because the syntax new double[ ]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3};

  • The program has a compile error because the syntax new double[ ]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}.

Erklärung

Frage 112 von 200

1

Do the following two programs produce the same result?

Program I:
public class Test {
public static void main(String[ ] args) {
int[ ] list = {1, 2, 3, 4, 5};
reverse(list);
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
}

public static void reverse(int[ ] list) {
int[ ] newList = new int[list.length];

for (int i = 0; i < list.length; i++)
newList[i] = list[list.length - 1 - i];

list = newList;
}
}

Program II:
public class Test {
public static void main(String[ ] args) {
int[ ] oldList = {1, 2, 3, 4, 5};
reverse(oldList);
for (int i = 0; i < oldList.length; i++)
System.out.print(oldList[i] + " ");
}

public static void reverse(int[ ] list) {
int[ ] newList = new int[list.length];

for (int i = 0; i < list.length; i++)
newList[i] = list[list.length - 1 - i];

list = newList;
}
}

Wähle eine der folgenden:

  • Yes

  • No

Erklärung

Frage 113 von 200

1

Which of the following statements is valid? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • int[ ] i = {3, 4, 3, 2};

  • char[ ] c = new char();

  • int i = new int(30);

  • char[ ] c = new char[4]{'a', 'b', 'c', 'd'};

  • double d[ ] = new double[30];

Erklärung

Frage 114 von 200

1

The selectionSort method is defined in this section. What is list1 after executing the following statements?

double[ ] list1 = {3.1, 3.1, 2.5, 6.4};
selectionSort(list1);

Wähle eine der folgenden:

  • list1 is 3.1, 2.5, 3.1, 6.4

  • list1 is 3.1, 3.1, 2.5, 6.4

  • list1 is 2.5 3.1, 3.1, 6.4

  • list1 is 6.4, 3.1, 3.1, 2.5

Erklärung

Frage 115 von 200

1

If a key is not in the list, the binarySearch method returns ________.

Wähle eine der folgenden:

  • -(insertion point + 1)

  • -insertion point

  • insertion point - 1

  • insertion point

Erklärung

Frage 116 von 200

1

How can you initialize an array of two characters to 'a' and 'b'? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • char[2] charArray = {'a', 'b'};

  • char[ ] charArray = new char[2]; charArray = {'a', 'b'};

  • char[ ] charArray = new char[ ]{'a', 'b'};

  • char[ ] charArray = {'a', 'b'};

Erklärung

Frage 117 von 200

1

What is the correct term for numbers[99]?

Wähle eine der folgenden:

  • array

  • array variable

  • indexed variable

  • index

  • index variable

Erklärung

Frage 118 von 200

1

If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________.

Wähle eine der folgenden:

  • 3.4

  • 5.5

  • 2.0

  • undefined

Erklärung

Frage 119 von 200

1

The ________ method sorts the array scores of the double[ ] type.

Wähle eine der folgenden:

  • java.util.Arrays.sort(scores)

  • java.util.Arrays(scores)

  • java.util.Arrays.sorts(scores)

  • Njava.util.Arrays.sortArray(scores)

Erklärung

Frage 120 von 200

1

Which of the following is incorrect? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • int a = new int[2];

  • int[ ] a = new int[2];

  • int a() = new int[2];

  • int[ ] a = new int(2);

  • int a[ ] = new int[2];

Erklärung

Frage 121 von 200

1

Which of the following statements are correct? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • char[ ][ ][ ] charArray = new char[2][2][ ];

  • char[ ][ ][ ] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};

  • char[2][2][ ] charArray = {'a', 'b'};

  • char[ ][ ][ ] charArray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}};

Erklärung

Frage 122 von 200

1

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

Wähle eine der folgenden:

  • 4 and 5

  • 5 and 5

  • 5 and 4

  • 4 and 4

Erklärung

Frage 123 von 200

1

Suppose a method p has the following heading:

public static int[ ][ ] p()

What return statement may be used in p()?

Wähle eine der folgenden:

  • return {1, 2, 3};

  • return 1;

  • return new int[ ]{1, 2, 3};

  • return int[ ]{1, 2, 3};

  • return new int[ ][ ]{{1, 2, 3}, {2, 4, 5}};

Erklärung

Frage 124 von 200

1

Assume int[ ] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 3) return?

Wähle eine der folgenden:

  • 1

  • -2

  • 2

  • 0

  • -1

Erklärung

Frage 125 von 200

1

What is the representation of the third element in an array called a?

Wähle eine der folgenden:

  • a(3)

  • a(2)

  • a[2]

  • a[3]

Erklärung

Frage 126 von 200

1

Which of the following statements are correct?

Wähle eine der folgenden:

  • char[2][ ] charArray = {{'a', 'b'}, {'c', 'd'}};

  • char[ ][ ] charArray = {{'a', 'b'}, {'c', 'd'}};

  • char[ ][ ] charArray = {'a', 'b'};

  • char[2][2] charArray = {{'a', 'b'}, {'c', 'd'}};

Erklärung

Frage 127 von 200

1

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

Wähle eine der folgenden:

  • 4, 5, and 6

  • 5, 5, and 5

  • 4, 5, and 4

  • 6, 5, and 4

Erklärung

Frage 128 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
boolean[ ][ ] x = new boolean[3][ ];
x[0] = new boolean[1]; x[1] = new boolean[2];
x[2] = new boolean[3];

System.out.println("x[2][2] is " + x[2][2]);
}
}

Wähle eine der folgenden:

  • The program has a runtime error because x[2][2] is null.

  • The program runs and displays x[2][2] is false.

  • The program has a compile error because new boolean[3][ ] is wrong.

  • The program runs and displays x[2][2] is true.

  • The program runs and displays x[2][2] is null.

Erklärung

Frage 129 von 200

1

Which of the following statements are correct to invoke the printMax method in Listing 6.5 in the textbook? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • printMax(1.0, 2.0, 2.0, 1.0, 4.0);

  • printMax(new double[ ]{1, 2, 3});

  • printMax(1, 2, 2, 1, 4);

  • printMax(new int[ ]{1, 2, 3});

Erklärung

Frage 130 von 200

1

In the following code, what is the printout for list2?

class Test {
public static void main(String[ ] args) {
int[ ] list1 = {1, 2, 3};
int[ ] list2 = {1, 2, 3};
list2 = list1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;
for (int i = 0; i < list2.length; i++)
System.out.print(list2[i] + " ");
}
}

Wähle eine der folgenden:

  • 0 1 2

  • 1 1 1

  • 1 2 3

  • 0 1 3

Erklärung

Frage 131 von 200

1

Which of the following errors is synchronous?

Wähle eine der folgenden:

  • All of the above.

  • Unsuccessful memory allocation.

  • Arithmetic overflow.

  • Divide by zero.

Erklärung

Frage 132 von 200

1

When an unchecked exception occurs in a method but is not caught:

Wähle eine der folgenden:

  • all local variables in that method go out of scope.

  • the method terminates.

  • All of the above.

  • the method-call stack is unwound.

Erklärung

Frage 133 von 200

1

What is displayed on the console when running the following program?

class Test {
public static void main(String[ ] args) {
try {
System.out.println("Welcome to Java");
int i = 0;
double y = 2.0 / i;
System.out.println("Welcome to HTML");
}
finally {
System.out.println("The finally clause is executed");
}
}
}

Wähle eine der folgenden:

  • Welcome to Java.

  • The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is executed.

  • None of the above.

  • Welcome to Java followed by The finally clause is executed in the next line.

Erklärung

Frage 134 von 200

1

What exception type does the following program throw?

public class Test {
public static void main(String[ ] args) {
String s = "abc";
System.out.println(s.charAt(3));
}
}

Wähle eine der folgenden:

  • ArrayIndexOutOfBoundsException

  • No exception

  • StringIndexOutOfBoundsException

  • ArithmeticException

  • ClassCastException

Erklärung

Frage 135 von 200

1

What is displayed on the console when running the following program?

class Test {
public static void main(String[ ] args) {
try {
System.out.println("Welcome to Java");
int i = 0;
int y = 2/i;
System.out.println("Welcome to Java");
}
catch (RuntimeException ex) {
System.out.println("Welcome to Java");
}
finally {
System.out.println("End of the block");
}
}
}

Wähle eine der folgenden:

  • The program displays Welcome to Java three times followed by End of the block.

  • The program displays Welcome to Java three times.

  • The program displays Welcome to Java two times.

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

Erklärung

Frage 136 von 200

1

What is displayed on the console when running the following program?

class Test {
public static void main(String[ ] args) {
try {
method();
System.out.println("After the method call");
}
catch (RuntimeException ex) {
System.out.println("RuntimeException");
}
catch (Exception ex) {
System.out.println("Exception");
}
}

static void method() throws Exception {
try {
String s = "5.6";
Integer.parseInt(s); // Cause a NumberFormatException

int i = 0;
int y = 2 / i;
System.out.println("Welcome to Java");
}
catch (NumberFormatException ex) {
System.out.println("NumberFormatException");
throw ex;
}
catch (RuntimeException ex) {
System.out.println("RuntimeException");
}
}
}

Wähle eine der folgenden:

  • The program has a compilation error.

  • The program displays NumberFormatException twice.

  • The program displays NumberFormatException followed by RuntimeException.

  • The program displays NumberFormatException followed by After the method call.

Erklärung

Frage 137 von 200

1

Which of the following statements is false?

Wähle eine der folgenden:

  • The class Throwable provides the method getMessage that returns the descriptive string stored in an exception.

  • The string returned from class Throwable’s getMessage method contains the name of the exception’s class.

  • The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.

  • All exceptions must derive from the class Throwable.

Erklärung

Frage 138 von 200

1

Analyze the following code:

class Test {
public static void main(String[ ] args) {
try {
int zero = 0;
int y = 2/zero;
try {
String s = "5.6";
Integer.parseInt(s); // Cause a NumberFormatException
}
catch(Exception e) {
}
}
catch(RuntimeException e) {
System.out.println(e);
}
}
}

Wähle eine der folgenden:

  • The program has a compilation error because Exception appears before RuntimeException.

  • A try-catch block cannot be embedded inside another try-catch block.

  • A good programming practice is to avoid nesting try-catch blocks, because nesting makes programs difficult to read. You can rewrite the program using only one try-catch block.

  • None of the above.

Erklärung

Frage 139 von 200

1

To catch an exception, the code that might throw the exception must be enclosed in a

Wähle eine der folgenden:

  • try block.

  • catch block.

  • throws block.

  • finally block.

Erklärung

Frage 140 von 200

1

An uncaught exception:

Wähle eine der folgenden:

  • is a possible exception that never actually occurs during the execution of the program.

  • is an exception that occurs for which the matching catch clause is empty.

  • is an exception that occurs for which there are no matching catch clauses.

  • is another term for a thrown exception.

Erklärung

Frage 141 von 200

1

What exception type does the following program throw?

public class Test {
public static void main(String[ ] args) {
int[ ] list = new int[5];
System.out.println(list[5]);
}
}

Wähle eine der folgenden:

  • ClassCastException

  • ArrayIndexOutOfBoundsException

  • No exception

  • ArithmeticException

  • StringIndexOutOfBoundsException

Erklärung

Frage 142 von 200

1

After a finally block has finished executing (and there are no exceptions to be handled):

Wähle eine der folgenden:

  • control returns to the throw point.

  • the application exits.

  • control proceeds to the first statement after the finally block.

  • control proceeds to the first statement after the last catch block.

Erklärung

Frage 143 von 200

1

What is displayed on the console when running the following program?

class Test {
public static void main(String[ ] args) {
try {
System.out.println("Welcome to Java");
int i = 0;
int y = 2/i;
System.out.println("Welcome to Java");
}
finally {
System.out.println("End of the block");
}

System.out.println("End of the block");
}
}

Wähle eine der folgenden:

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

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

  • The program displays Welcome to Java three times followed by End of the block.

  • The program displays Welcome to Java and End of the block, and then terminates because of an unhandled exception.

Erklärung

Frage 144 von 200

1

Which of the following is not included in an exception's stack trace?

Wähle eine der folgenden:

  • Instructions on handling the exception.

  • A descriptive message for the exception.

  • The method-call stack at the time the exception occurred.

  • The name of the exception.

Erklärung

Frage 145 von 200

1

Which of the following statements is false?

Wähle eine der folgenden:

  • The finally block and try block can appear in any order.

  • A finally block is placed after the last catch block.

  • A finally block typically releases resources acquired in the corresponding try block.

  • A finally block is optional.

Erklärung

Frage 146 von 200

1

Attributes of a class are also known as:

Wähle eine der folgenden:

  • Constructors.

  • Fields.

  • Local variables.

  • Classes.

Erklärung

Frage 147 von 200

1

________ is invoked to create an object.

Wähle eine der folgenden:

  • A method with the void return type

  • A method with a return type

  • The main method

  • A constructor

Erklärung

Frage 148 von 200

1

What type of methods allow a client of a class to assign values to a private instance variable?

Wähle eine der folgenden:

  • Assign methods.

  • Replace methods.

  • Get methods.

  • Set methods.

Erklärung

Frage 149 von 200

1

Which of the following statement is most accurate? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • A reference variable refers to an object.

  • An object may contain the references of other objects.

  • A reference variable is an object.

  • An object may contain other objects.

Erklärung

Frage 150 von 200

1

What is the value of myCount.count displayed?

public class Test {
public static void main(String[ ] args) {
Count myCount = new Count();
int times = 0;

for (int i=0; i<100; i++)
increment(myCount, times);

System.out.println(
"myCount.count = " + myCount.count);
System.out.println("times = "+ times);
}

public static void increment(Count c, int times) {
c.count++;
times++;
}
}

class Count {
int count;

Count(int c) {
count = c;
}

Count() {
count = 1;
}
}

Wähle eine der folgenden:

  • 98

  • 99

  • 100

  • 101

Erklärung

Frage 151 von 200

1

Suppose you wish to provide an accessor method for a boolean property finished, what signature of the method should be?

Wähle eine der folgenden:

  • public void getFinished()

  • public boolean getFinished()

  • public boolean isFinished()

  • public void isFinished()

Erklärung

Frage 152 von 200

1

What is the printout of the third println statement in the main method?

public class Foo {
int i;
static int s;

public static void main(String[ ] args) {
Foo f1 = new Foo();
System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s);
Foo f2 = new Foo();
System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s);
Foo f3 = new Foo();
System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s);
}

public Foo() {
i++;
s++;
}
}

Wähle eine der folgenden:

  • f3.i is 1 f3.s is 1

  • f3.i is 3 f3.s is 3

  • f3.i is 3 f3.s is 1

  • f3.i is 1 f3.s is 2

  • f3.i is 1 f3.s is 3

Erklärung

Frage 153 von 200

1

Sending a message to an object means that:

Wähle eine der folgenden:

  • Neither (a) nor (b).

  • You access a variable of the object.

  • You call a method of the object.

  • Both (a) and (b).

Erklärung

Frage 154 von 200

1

Analyze the following code and choose the best answer:

public class Foo {
private int x;

public static void main(String[ ] args) {
Foo foo = new Foo();
System.out.println(foo.x);
}
}

Wähle eine der folgenden:

  • Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code.

  • Since x is private, it cannot be accessed from an object foo.

  • You cannot create a self-referenced object; that is, foo is created inside the class Foo.

  • Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code.

Erklärung

Frage 155 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
double radius;
final double PI= 3.15169;
double area = radius * radius * PI;
System.out.println("Area is " + area);
}
}

Wähle eine der folgenden:

  • The program has compile errors because the variable radius is not initialized.

  • The program compiles and runs fine.

  • The program has no compile errors but will get a runtime error because radius is not initialized.

  • The program has a compile error because a constant PI is defined inside a method.

Erklärung

Frage 156 von 200

1

Analyze the following code:

public class Test {
private int t;

public static void main(String[ ] args) {
int x;
System.out.println(t);
}
}

Wähle eine der folgenden:

  • The program compiles and runs fine.

  • t is non-static and it cannot be referenced in a static context in the main method.

  • The variable x is not initialized and therefore causes errors.

  • The variable t is private and therefore cannot be accessed in the main method.

  • The variable t is not initialized and therefore causes errors.

Erklärung

Frage 157 von 200

1

Analyze the following code:

public class Test {
public static void main(String args[ ]) {
NClass nc = new NClass();
nc.t = nc.t++;
}
}

class NClass {
int t;
private NClass() {
}
}

Wähle eine der folgenden:

  • The program has a compilation error because the NClass class has a private constructor.

  • The program compiles and runs fine.

  • The program does not compile because the parameter list of the main method is wrong.

  • The program compiles, but has a runtime error because t has no initial value.

Erklärung

Frage 158 von 200

1

A method that is associated with an individual object is called ________.

Wähle eine der folgenden:

  • an object method

  • a static method

  • a class method

  • an instance method

Erklärung

Frage 159 von 200

1

When invoking a method with an object argument, ________ is passed.

Wähle eine der folgenden:

  • the contents of the object

  • a copy of the object

  • the reference of the object

  • the object is copied, then the reference of the copied object

Erklärung

Frage 160 von 200

1

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

Wähle eine oder mehr der folgenden:

  • Use the private modifier to encapsulate data fields.

  • Encapsulating data fields helps prevent programming errors.

  • Encapsulating data fields makes the program easy to maintain.

  • Encapsulating data fields makes the program short.

Erklärung

Frage 161 von 200

1

What is the printout for the first statement in the main method?

public class Foo {
static int i = 0;
static int j = 0;

public static void main(String[ ] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}

k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}

Wähle eine der folgenden:

  • i + j is 23

  • i + j is 22

  • i + j is 5

  • i + j is 6

Erklärung

Frage 162 von 200

1

In the UML, a class's attributes are placed in the ________ compartment of the class's rectangle.

Wähle eine der folgenden:

  • third

  • second

  • bottom

  • first

Erklärung

Frage 163 von 200

1

You can declare two variables with the same name in ________.

Wähle eine der folgenden:

  • different methods in a class

  • a method one as a formal parameter and the other as a local variable

  • two nested blocks in a method (two nested blocks means one being inside the other)

  • a block

Erklärung

Frage 164 von 200

1

We can derive many of the operations of each class by examining the key ________ and ________ in the requirements documents.

Wähle eine der folgenden:

  • nouns. noun phrases.

  • objectives, objective phrases.

  • verbs, verb phrases.

  • Both a and b.

Erklärung

Frage 165 von 200

1

The sequence of messages in a communication diagram progresses:

Wähle eine der folgenden:

  • alphabetically.

  • None of the above.

  • in numerical order from least to greatest.

  • Both of the above.

Erklärung

Frage 166 von 200

1

Objects are modeled in the UML as         containing names in the form         .

Wähle eine der folgenden:

  • rectangles, : ClassName.

  • rectangles, objectName : ClassName.

  • ovals, objectName : ClassName.

  • ovals, : ClassName.

Erklärung

Frage 167 von 200

1

In the UML, the         diagram emphasizes which objects participate in collaborations.

Wähle eine der folgenden:

  • collaboration.

  • participation.

  • sequence.

  • communication.

Erklärung

Frage 168 von 200

1

UML ________ model several states of an object and show under what circumstances the object changes state.

Wähle eine der folgenden:

  • diagrams.

  • state machine diagrams.

  • machine diagrams.

  • activity diagrams.

Erklärung

Frage 169 von 200

1

What is the printout for the second statement in the main method?

public class Foo {
static int i = 0;
static int j = 0;

public static void main(String[ ] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}

k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}

Wähle eine der folgenden:

  • k is 0

  • k is 1

  • k is 3

  • k is 2

Erklärung

Frage 170 von 200

1

Which diagram is also called a collaboration diagram.

Wähle eine der folgenden:

  • State machine diagram.

  • Sequence diagram.

  • Activity diagram.

  • Communication diagram.

Erklärung

Frage 171 von 200

1

Analyze the following code: (Choose all that apply.)

class Test {
private double i;

public Test(double i) {
this.t();
this.i = i;
}

public Test() {
System.out.println("Default constructor");
this(1);
}

public void t() {
System.out.println("Invoking t");
}
}

Wähle eine oder mehr der folgenden:

  • this(1) must be replaced by this(1.0).

  • this.i may be replaced by i.

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

  • this.t() may be replaced by t().

Erklärung

Frage 172 von 200

1

What is a message between collaborating objects called in the UML?

Wähle eine der folgenden:

  • communication call.

  • collaboration call.

  • synchronous call.

  • asynchronous call.

Erklärung

Frage 173 von 200

1

Communication diagrams contain an object's lifeline. Which of the following is true of the object's lifeline?

Wähle eine der folgenden:

  • Actions occur along an object's lifeline in chronological order from top to bottom.

  • The lifeline represents the progression of time.

  • All of the above are true.

  • The line is dotted.

Erklärung

Frage 174 von 200

1

An activation indicates that:

Wähle eine der folgenden:

  • an object is sending a message.

  • an object is being created.

  • an object has completed executing.

  • an object is executing.

Erklärung

Frage 175 von 200

1

The use case diagram models ________.

Wähle eine der folgenden:

  • each software life cycle by repeating one or more stages several times via use cases.

  • each software life cycle stage in succession.

  • the interactions between implementations and testing.

  • the interactions between a system's client and one of the system's capabilities.

Erklärung

Frage 176 von 200

1

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

Wähle eine oder mehr der folgenden:

  • Dynamic binding can apply to static methods.

  • The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compilation time.

  • A method may be implemented in several subclasses. The Java Virtual Machine dynamically binds the implementation of the method at runtime.

  • You can always pass an instance of a subclass to a parameter of its superclass type. This feature is known as polymorphism.

  • Dynamic binding can apply to instance methods.

Erklärung

Frage 177 von 200

1

Which method changes the text the label displays?

Wähle eine der folgenden:

  • changeText.

  • changeLabel.

  • setLabel.

  • setText.

Erklärung

Frage 178 von 200

1

Composition means ________.

Wähle eine der folgenden:

  • that a class can extend another class

  • that a variable of supertype can refer to a subtype object

  • that data fields should be declared private

  • that a class can contain another class

Erklärung

Frage 179 von 200

1

Every object in Java knows its own class and can access this information through method ___________________ .

Wähle eine der folgenden:

  • getClass.

  • objectInformation.

  • getInformation.

  • objectClass.

Erklärung

Frage 180 von 200

1

Analyze the following code: (Choose all that apply.)

import java.util.StringTokenizer;

public class A extends StringTokenizer {
}

Wähle eine oder mehr der folgenden:

  • The program would compile fine if you add the following constructor into A: A(String s) { super(s); }

  • The program has a compilation error because A does not have a default constructor.

  • The program would compile fine if you add the following constructor into A: A(String s) { }

  • The program has a compilation error because the default constructor of A invokes the default constructor of StringTokenizer, but StringTokenizer does not have a default constructor.

Erklärung

Frage 181 von 200

1

The default implementation of method clone of Object performs a ________.

Wähle eine der folgenden:

  • full copy.

  • shallow copy.

  • empty copy.

  • deep copy.

Erklärung

Frage 182 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
String s = new String("Welcome to Java");
Object o = s;
String d = (String)o;
}
}

Wähle eine der folgenden:

  • When casting o to s in String d = (String)o, a new object is created.

  • When assigning s to o in Object o = s, a new object is created.

  • When casting o to s in String d = (String)o, the contents of o is changed.

  • s, o, and d reference the same String object.

Erklärung

Frage 183 von 200

1

Inheritance is also known as the

Wähle eine der folgenden:

  • "is-a" relationship.

  • "knows-a" relationship.

  • "uses-a" relationship.

  • "has-a" relationship.

Erklärung

Frage 184 von 200

1

Polymorphism enables you to:

Wähle eine der folgenden:

  • program in the general.

  • hide information from the user.

  • program in the specific.

  • absorb attributes and behavior from previous classes.

Erklärung

Frage 185 von 200

1

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

Wähle eine oder mehr der folgenden:

  • "class A extends B" means B is a subclass of A.

  • "class A extends B" means A is a subclass of B.

  • A subclass is a subset of a superclass.

  • A subclass is usually extended to contain more functions and more detailed information than its superclass.

Erklärung

Frage 186 von 200

1

Classes and methods are declared final for all but the following reasons:

Wähle eine der folgenden:

  • final methods allow inlining the code.

  • final methods can improve performance.

  • final methods are static.

  • final methods and classes prevent further inheritance.

Erklärung

Frage 187 von 200

1

When a superclass variable refers to a subclass object and a method is called on that object, the proper implementation is determined at execution time. What is the process of determining the correct method to call?

Wähle eine der folgenden:

  • execution binding.

  • execution time binding.

  • just-in-time binding.

  • late binding.

Erklärung

Frage 188 von 200

1

Which of the following is the superclass constructor call syntax?

Wähle eine der folgenden:

  • keyword super, followed by a dot (.) .

  • keyword super, followed by a dot and the superclass constructor name.

  • None of the above.

  • keyword super, followed by a set of parentheses containing the superclass constructor arguments.

Erklärung

Frage 189 von 200

1

Which of the statements regarding the super keyword is incorrect?

Wähle eine der folgenden:

  • You can use super to invoke a super class method.

  • You can use super to invoke a super class constructor.

  • You can use super.super.p to invoke a method in superclass's parent class.

  • You cannot invoke a method in superclass's parent class.

Erklärung

Frage 190 von 200

1

Which statement best describes the relationship between superclass and subclass types?

Wähle eine der folgenden:

  • A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.

  • A superclass reference can be assigned to a subclass variable, but a subclass reference cannot be assigned to a superclass variable.

  • A subclass reference can be assigned to a superclass variable and a superclass reference can be assigned to a subclass variable.

  • A subclass reference cannot be assigned to a superclass variable and a superclass reference cannot be assigned to a subclass variable.

Erklärung

Frage 191 von 200

1

A Java character is stored in ________.

Wähle eine der folgenden:

  • two bytes

  • four bytes

  • one byte

  • three bytes

Erklärung

Frage 192 von 200

1

Which statement is false?

Wähle eine der folgenden:

  • Unless directed otherwise, the computer executes Java statements one after the other in the order in which they are written.

  • Activity diagrams normally show the Java code that implements the activity.

  • Like pseudocode, activity diagrams help programmers develop and represent algorithms.

  • The arrows in the activity diagram represent transitions, which indicate the order in which the actions represented by the action states occur.

Erklärung

Frage 193 von 200

1

Keyword ________ indicates the inheritance relationship.

Wähle eine der folgenden:

  • extends

  • inherits

  • super

  • parent

Erklärung

Frage 194 von 200

1

What is the result value of c at the end of the following code segment?

int c = 8;
c++;
++c;
c %= 5;

Wähle eine der folgenden:

  • 0.

  • 1.

  • 3.

  • None of the above.

Erklärung

Frage 195 von 200

1

Which statement is false?

Wähle eine der folgenden:

  • To ensure that the operands are of the same type, Java performs implicit conversion on selected operands.

  • Cast operators are unary operators.

  • Cast operators associate from right to left and are one level lower in precedence than the multiplicative operators.

  • Cast operators are formed by placing parentheses around the name of a type.

Erklärung

Frage 196 von 200

1

Which of the following would not be used to clarify a dangling-else?

Wähle eine der folgenden:

  • Indentation.

  • Parentheses ().

  • Braces {}.

  • Comment //.

Erklärung

Frage 197 von 200

1

To assign a double variable d to a float variable x, you write

Wähle eine der folgenden:

  • x = (long)d

  • x = d;

  • x = (float)d;

  • x = (int)d;

Erklärung

Frage 198 von 200

1

Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?

Wähle eine der folgenden:

  • System.out.println(i);

  • System.out.println(i + " ");

  • System.out.println((int)i);

  • System.out.println((char)i);

Erklärung

Frage 199 von 200

1

What is the number of iterations in the following loop:

for (int i = 1; i < n; i++) {
// iteration
}

Wähle eine der folgenden:

  • n - 1

  • n

  • n + 1

  • 2*n

Erklärung

Frage 200 von 200

1

Consider the following Java statements:

int x = 9;
double y = 5.3;
result = calculateValue( x, y );

Wähle eine der folgenden:

  • A method is called with its name and parentheses.

  • x and y are parameters.

  • Copies of x and y are passed to the method calculateValue().

  • x and y are arguments.

Erklärung