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

Practice quiz for Java 1 at Gwinnett Tech College.

1132
4
0
Ummm No
Erstellt von Ummm No vor fast 9 Jahre
Schließen

Java Practice 2

Frage 1 von 200

1

To add a value 1 to variable x, you write (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • x += 1;

  • x = 1 + x;

  • x := 1;

  • x = x + 1;

  • 1 + x = x;

Erklärung

Frage 2 von 200

1

An overloaded method is one that

Wähle eine der folgenden:

  • has a different name than another method, but the same parameters.

  • has the same name as another method, but different parameters (by number, types or order of the types).

  • has the same name and parameters as a method defined in another class.

  • has the same name and parameters, but a different return type as another method.

Erklärung

Frage 3 von 200

1

In Java, the word true is ________.

Wähle eine der folgenden:

  • same as value 0

  • same as value 1

  • a Boolean literal

  • a Java keyword

Erklärung

Frage 4 von 200

1

The ________ method parses a string s to a double value.

Wähle eine der folgenden:

  • double.parseDouble(s);

  • double.parse(s);

  • Double.parsedouble(s);

  • Double.parseDouble(s);

Erklärung

Frage 5 von 200

1

Suppose variable gender is MALE and age equals 60, how is the expression
( gender == FEMALE ) && ( age >= 65 )
evaluated?

Wähle eine der folgenden:

  • The condition ( gender == FEMALE ) is evaluated first and the evaluation stops immediately.

  • The condition ( age >= 65 ) is evaluated first and the evaluation stops immediately.

  • Both conditions are evaluated, from left to right.

  • Both conditions are evaluated, from right to left.

Erklärung

Frage 6 von 200

1

Will the following program terminate?

int balance = 10;

while (true) {
if (balance < 9) continue;
balance = balance - 9;
}

Wähle eine der folgenden:

  • Yes

  • No

Erklärung

Frage 7 von 200

1

What is the output of the following code?

boolean even = false;
System.out.println((even ? "true" : "false"));

Wähle eine der folgenden:

  • true

  • true false

  • false

  • nothing

Erklärung

Frage 8 von 200

1

Which command compiles the Java source code file Welcome.java?

Wähle eine der folgenden:

  • cd Welcome.java

  • javac Welcome.java

  • java Welcome.java

  • compile Welcome.java

Erklärung

Frage 9 von 200

1

The following code fragment reads in two numbers: (Choose all that apply.)

Scanner input = new Scanner(System.in);
int i = input.nextInt();
double d = input.nextDouble();

What are the correct ways to enter these two numbers?

Wähle eine oder mehr der folgenden:

  • Enter an integer, an Enter key, a double value, and then the Enter key.

  • Enter an integer, a space, a double value, and then the Enter key.

  • Enter an integer, two spaces, a double value, and then the Enter key.

  • Enter a numeric value with a decimal point, a space, an integer, and then the Enter key.

Erklärung

Frage 10 von 200

1

Suppose s1 and s2 are two strings. Which of the following statements or expressions is incorrect? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • boolean b = s1.compareTo(s2);

  • char c = s1[0];

  • char c = s1.charAt(s1.length());

  • String s3 = s1 - s2;

Erklärung

Frage 11 von 200

1

Which statement is true?

Wähle eine der folgenden:

  • A while statement cannot be nested inside another while statement.

  • An if statement cannot be nested inside another if statement.

  • A while statement cannot be nested inside an if statement.

  • None of the above is true.

Erklärung

Frage 12 von 200

1

What is output by the following Java code segment?

int temp;
temp = 180;

while ( temp != 80 )
{
if ( temp > 90 )
{
System.out.print( "This porridge is too hot! " );

// cool down
temp = temp – ( temp > 150 ? 100 : 20 );
} // end if
else
{
if ( temp < 70 )
{
System.out.print(
"This porridge is too cold! ");

// warm up
temp = temp + (temp < 50 ? 30 : 20);
} // end if
} // end else
} // end while

if ( temp == 80 )
System.out.println( "This porridge is just right!" );

Wähle eine der folgenden:

  • This porridge is too cold! This porridge is just right!

  • This porridge is too hot! This porridge is just right!

  • This porridge is just right!

  • None of the above.

Erklärung

Frage 13 von 200

1

Suppose s is a string with the value "java". What will be assigned to x if you execute the following code?

char x = s.charAt(4);

Wähle eine der folgenden:

  • 'a'

  • 'v'

  • Nothing will be assigned to x, because the execution causes the runtime error StringIndexOutofBoundsException.

Erklärung

Frage 14 von 200

1

Which of these statements best defines scope?

Wähle eine der folgenden:

  • Scope refers to the classes that have access to a variable.

  • Scope determines whether a variable's value can be altered.

  • Scoping allows the programmer to use a class without using its fully qualified name.

  • Scope is the portion of a program that can refer to an entity by its simple name.

Erklärung

Frage 15 von 200

1

What is the value of (double)5/2?

Wähle eine der folgenden:

  • 2.5

  • 2

  • 3

  • 2.0

  • 3.0

Erklärung

Frage 16 von 200

1

What does the expression x %= 10 do?

Wähle eine der folgenden:

  • Adds 10 to the value of x, and stores the result in x.

  • Divides x by 10 and stores the remainder in x.

  • Divides x by 10 and stores the integer result in x.

  • None of the above.

Erklärung

Frage 17 von 200

1

Which of the following is not a package in the Java API?

Wähle eine der folgenden:

  • java.characters.

  • java.awt.

  • javax.swing.event.

  • java.lang.

Erklärung

Frage 18 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

  • 9

  • 10

Erklärung

Frage 19 von 200

1

Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ________, which stores elements in last-in first-out fashion.

Wähle eine der folgenden:

  • a stack

  • an array

  • a heap

  • storage area

Erklärung

Frage 20 von 200

1

Counter-controlled repetition requires

Wähle eine der folgenden:

  • A control variable and initial value.

  • A control variable increment (or decrement).

  • A condition that tests for the final value of the control variable.

  • All of the above.

Erklärung

Frage 21 von 200

1

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

Wähle eine oder mehr der folgenden:

  • char c = 'd';

  • char c = "100";

  • char c = "d";

  • char c = 100;

Erklärung

Frage 22 von 200

1

To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy?

Wähle eine der folgenden:

  • add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable whose initial value is 0.

  • add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0.

Erklärung

Frage 23 von 200

1

(int)(Math.random() * (65535 + 1)) returns a random number ________.

Wähle eine der folgenden:

  • between 1 and 65535

  • between 0 and 65536

  • between 0 and 65535

  • between 1 and 65536

Erklärung

Frage 24 von 200

1

What is the return value of "SELECT".substring(4, 4)?

Wähle eine der folgenden:

  • T

  • C

  • an empty string

  • E

Erklärung

Frage 25 von 200

1

What is the value of (double)(5/2)?

Wähle eine der folgenden:

  • 2

  • 2.0

  • 3

  • 2.5

  • 3.0

Erklärung

Frage 26 von 200

1

Which of the following statements will print a single line containing "hello there"?

Wähle eine der folgenden:

  • System.out.println( "hello" );
    System.out.println( " there" );

  • System.out.println( "hello" , " there" );

  • System.out.println( "hello" );
    System.out.print( " there" );

  • System.out.print( "hello" );
    System.out.println( " there" );

Erklärung

Frage 27 von 200

1

Which of the following operators are right-associative?

Wähle eine der folgenden:

  • *

  • %

  • &&

  • +

  • =

Erklärung

Frage 28 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");
}
finally {
System.out.println("The finally clause is executed");
}
}
}

Wähle eine der folgenden:

  • The finally clause is executed

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

  • None of the above

  • Welcome to Java

Erklärung

Frage 29 von 200

1

Which of the following exceptions is a checked exception?

Wähle eine der folgenden:

  • ArithmeticException.

  • IOException.

  • InputMismatchException.

  • RuntimeException.

Erklärung

Frage 30 von 200

1

What exception type does the following program throw?

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

Wähle eine der folgenden:

  • ClassCastException

  • No exception

  • ArithmeticException

  • StringIndexOutOfBoundsException

  • ArrayIndexOutOfBoundsException

Erklärung

Frage 31 von 200

1

What is wrong in the following program?

class Test {
public static void main (String[ ] args) {
try {
System.out.println("Welcome to Java");
}
}
}

Wähle eine der folgenden:

  • You cannot have a try block without a catch block.

  • A method call that does not declare exceptions cannot be placed inside a try block.

  • You cannot have a try block without a catch block or a finally block.

  • Nothing is wrong.

Erklärung

Frage 32 von 200

1

Which of the following statements is true?

Wähle eine der folgenden:

  • The new exception class should extend RuntimeException if the program should be required to handle the exception.

  • Using existing exceptions makes the program less robust.

  • Always create your own exception classes.

  • Like any other class, an exception class can contain fields and methods.

Erklärung

Frage 33 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 HTML");
}
finally {
System.out.println("The finally clause is executed");
}
}
}

Wähle eine der folgenden:

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

  • Welcome to Java.

  • None of the above.

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

Erklärung

Frage 34 von 200

1

What is the difference between a try block and a try statement?

Wähle eine der folgenden:

  • A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword.

  • The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.

  • There is no difference; the terms can be used interchangeably.

  • The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.

Erklärung

Frage 35 von 200

1

If the catch-or-declare requirement for a checked exception is not satisfied:

Wähle eine der folgenden:

  • a stack trace will be displayed, along with a message indicating that the exception must be caught.

  • a stack trace will be displayed indicating the exception that has occurred and where it occurred.

  • the compiler will issue an error message indicating that the exception must be caught or declared.

  • the compiler will issue an error message indicating that the exception must be caught.

Erklärung

Frage 36 von 200

1

When an exception occurs it is said to have been:

Wähle eine der folgenden:

  • handled.

  • thrown.

  • caught.

  • declared.

Erklärung

Frage 37 von 200

1

Exceptions can be thrown by:

Wähle eine der folgenden:

  • All of the above.

  • code in a try block.

  • the Java Virtual Machine.

  • calls from a try block to other methods.

Erklärung

Frage 38 von 200

1

Analyze the following code:

class Test {
public static void main(String[ ] args)
throws MyException {
System.out.println("Welcome to Java");
}
}

class MyException extends Error {
}

Wähle eine der folgenden:

  • You cannot declare an exception in the main method.

  • You declared an exception in the main method, but you did not throw it.

  • The program has a compilation error.

  • You should not declare a class that extends Error, because Error raises a fatal error that terminates the program.

Erklärung

Frage 39 von 200

1

The following code causes Java to throw ________.
int number = Integer.MAX_VALUE + 1;

Wähle eine der folgenden:

  • Error

  • RuntimeException

  • no exceptions

  • Exception

  • Throwable

Erklärung

Frage 40 von 200

1

A Java exception is an instance of ________.

Wähle eine der folgenden:

  • RuntimeException

  • Error

  • NumberFormatException

  • Exception

  • Throwable

Erklärung

Frage 41 von 200

1

Which of the following statements is true?

Wähle eine der folgenden:

  • The code in a finally block is executed only if an exception occurs.

  • The code in a finally block is executed only if an exception does not occur.

  • None of the above are true.

  • The code in a finally block is executed only if there are no catch blocks.

Erklärung

Frage 42 von 200

1

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following method will cause runtime errors? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • x.get(1)

  • x.size()

  • x.remove(2)

  • x.get(2)

  • x.set(2, "New York");

Erklärung

Frage 43 von 200

1

Which keyword is used to specify that a class will define the methods of an interface?

Wähle eine der folgenden:

  • implements.

  • extends.

  • defines.

  • uses.

Erklärung

Frage 44 von 200

1

A(n) ____________________ class cannot be instantiated.

Wähle eine der folgenden:

  • polymorphic.

  • abstract.

  • concrete.

  • final.

Erklärung

Frage 45 von 200

1

Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass's method causes ________.

Wähle eine der folgenden:

  • a syntax error.

  • a compile-time error.

  • a runtime error.

  • infinite recursion.

Erklärung

Frage 46 von 200

1

The equals method is defined in the Object class. Which of the following is correct to override it in the String class?

Wähle eine der folgenden:

  • public static boolean equals(String other)

  • public boolean equals(String other)

  • public static boolean equals(Object other)

  • public boolean equals(Object other)

Erklärung

Frage 47 von 200

1

Inheritance means ________.

Wähle eine der folgenden:

  • 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

  • that a class can extend another class

Erklärung

Frage 48 von 200

1

Analyze the following code:

Cylinder cy = new Cylinder(1, 1);
Circle c = cy;

Wähle eine der folgenden:

  • The code has a runtime error.

  • The code has a compile error.

  • The code is fine.

Erklärung

Frage 49 von 200

1

Encapsulation means ________.

Wähle eine der folgenden:

  • that a class can extend another class

  • that data fields should be declared private

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

  • that a class can contain another class

Erklärung

Frage 50 von 200

1

private fields of a superclass can be accessed in a subclass

Wähle eine der folgenden:

  • by calling public or protected methods declared in the superclass.

  • All of the above.

  • directly.

  • by calling private methods declared in the superclass.

Erklärung

Frage 51 von 200

1

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following method will cause the list to become [Beijing]? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • x.remove(1)

  • x.remove("Singapore")

  • x.remove(0)

  • x.remove(2)

Erklärung

Frage 52 von 200

1

You can assign ________ to a variable of Object[ ] type. (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • new java.util.Date[100]

  • new String[100]

  • new double[100]

  • new char[100]

  • new int[100]

Erklärung

Frage 53 von 200

1

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

Wähle eine oder mehr der folgenden:

  • A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated.

  • Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them.

  • It is a compilation error if two methods differ only in return type in the same class.

  • To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass.

  • A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden.

Erklärung

Frage 54 von 200

1

Given the following code:

class C1 {}
class C2 extends C1 { }
class C3 extends C2 { }
class C4 extends C1 {}

C1 c1 = new C1();
C2 c2 = new C2();
C3 c3 = new C3();
C4 c4 = new C4();

Which of the following expressions evaluates to false?

Wähle eine der folgenden:

  • c4 instanceof C2

  • c1 instanceof C1

  • c3 instanceof C1

  • c2 instanceof C1

Erklärung

Frage 55 von 200

1

Object-oriented programming allows you to derive new classes from existing classes. This is called ________.

Wähle eine der folgenden:

  • generalization

  • encapsulation

  • inheritance

  • abstraction

Erklärung

Frage 56 von 200

1

What is the printout for the third 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:

  • j is 3

  • j is 1

  • j is 2

  • j is 0

Erklärung

Frage 57 von 200

1

The UML represents operations by listing the operation name, followed by a ________-separated list of parameters in parentheses, a ________ and the return type.

Wähle eine der folgenden:

  • comma, colon.

  • colon, semicolon.

  • colon, colon.

  • comma, semicolon.

Erklärung

Frage 58 von 200

1

Analyze the following code:

class Circle {
private double radius;

public Circle(double radius) {
radius = radius;
}
}

Wähle eine der folgenden:

  • The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0.

  • The program has a compilation error because you cannot assign radius to radius.

  • The program does not compile because Circle does not have a default constructor.

  • The program has a compilation error because it does not have a main method.

Erklärung

Frage 59 von 200

1

Which diagram models system structure?

Wähle eine der folgenden:

  • State machine diagram.

  • Activity diagram.

  • Class diagram.

  • Sequence diagram.

Erklärung

Frage 60 von 200

1

Which of the following is the first stage of the software life cycle?

Wähle eine der folgenden:

  • testing.

  • implementation.

  • requirements gathering.

  • design.

Erklärung

Frage 61 von 200

1

Analyze the following code.

public class Test {
int x;

public Test(String t) {
System.out.println("Test");
}

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

Wähle eine der folgenden:

  • The program has a compile error because System.out.println method cannot be invoked from the constructor.

  • The program has a compile error because Test does not have a default constructor.

  • The program has a compile error because you cannot create an object from the class that defines the object.

  • The program has a compile error because x has not been initialized.

Erklärung

Frage 62 von 200

1

Analyze the following code.

public class Test {
int x;

public Test(String t) {
System.out.println("Test");
}

public static void main(String[ ] args) {
Test test = null;
System.out.println(test.x);
}
}

Wähle eine der folgenden:

  • The program has a compile error because you cannot create an object from the class that defines the object.

  • The program has a compile error because x has not been initialized.

  • The program has a compile error because test is not initialized.

  • The program has a runtime NullPointerException because test is null while executing test.x.

  • The program has a compile error because Test does not have a default constructor.

Erklärung

Frage 63 von 200

1

Assume java.util.Date[ ] dates = new java.util.Date[10], which of the following statements are true? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • dates is null.

  • dates = new Date() is fine, which creates a new Date object and assigns to dates.

  • dates = new java.util.Date[5] is fine, which assigns a new array to dates.

  • dates[0] is null.

Erklärung

Frage 64 von 200

1

The java.util.Date class is introduced in this section. Which of the following code creates an object of the Date class? (Choose all that apply.)

A:
public class Test {
public Test() {
new java.util.Date();
}
}

B:
public class Test {
public Test() {
java.util.Date date = new java.util.Date();
}
}

Wähle eine oder mehr der folgenden:

  • B

  • A

  • neither

Erklärung

Frage 65 von 200

1

________ is a construct that defines objects of the same type.

Wähle eine der folgenden:

  • A class

  • A method

  • A data field

  • An object

Erklärung

Frage 66 von 200

1

Which two Java primitive types store floating-point numbers?

Wähle eine der folgenden:

  • decimal and float.

  • point and double.

  • decimal and point.

  • float and double.

Erklärung

Frage 67 von 200

1

What is the printout of the second 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:

  • f2.i is 2 f2.s is 2

  • f2.i is 1 f2.s is 2

  • f2.i is 2 f2.s is 1

  • f2.i is 1 f2.s is 1

Erklärung

Frage 68 von 200

1

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

Wähle eine oder mehr der folgenden:

  • Constructors are invoked using the new operator when an object is created.

  • At least one constructor must always be defined explicitly.

  • Constructors do not have a return type, not even void.

  • A default no-arg constructor is provided automatically if no constructors are explicitly declared in the class.

  • Constructors must have the same name as the class itself.

Erklärung

Frage 69 von 200

1

An object is an instance of a ________.

Wähle eine der folgenden:

  • method

  • program

  • data

  • class

Erklärung

Frage 70 von 200

1

When you pass an array to a method, the method receives ________.

Wähle eine der folgenden:

  • the length of the array

  • the reference of the array

  • a copy of the first element

  • a copy of the array

Erklärung

Frage 71 von 200

1

Assume int[ ] t = {1, 2, 3, 4}. What is t.length?

Wähle eine der folgenden:

  • 4

  • 0

  • 5

  • 3

Erklärung

Frage 72 von 200

1

Analyze the following code:

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

x = new int[2];

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

Wähle eine der folgenden:

  • The program displays 0 0 3 4

  • The program displays 0 0

  • The program displays 0 0 0 0

  • The program displays 1 2 3 4

Erklärung

Frage 73 von 200

1

Analyze the following code.

int[ ] list = new int[5];
list = new int[6];

Wähle eine der folgenden:

  • The code has runtime errors because the variable list cannot be changed once it is assigned.

  • The code has compile errors because you cannot assign a different size array to list.

  • The code has compile errors because the variable list cannot be changed once it is assigned.

  • The code can compile and run fine. The second line assigns a new array to list.

Erklärung

Frage 74 von 200

1

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

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 < list1.length; i++)
System.out.print(list1[i] + " ");
}
}

Wähle eine der folgenden:

  • 0 1 2

  • 1 2 3

  • 1 1 1

  • 0 1 3

Erklärung

Frage 75 von 200

1

How many elements are in array double[ ] list = new double[5]?

Wähle eine der folgenden:

  • 0

  • 4

  • 5

  • 6

Erklärung

Frage 76 von 200

1

The selectionSort method is defined in this section. Assume list is {3.1, 3.1, 2.5, 6.4, 2.1}, what is the content of list after the first iteration of the outer loop in the method?

Wähle eine der folgenden:

  • 2.1, 2.5, 3.1, 3.1, 6.4

  • 2.5, 3.1, 3.1, 6.4, 2.1

  • 3.1, 3.1, 2.5, 2.1, 6.4

  • 3.1, 3.1, 2.5, 6.4, 2.1

Erklärung

Frage 77 von 200

1

Analyze the following code:

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

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

public static long xmethod(long n) {
System.out.println("long");
return n;
}
}

Wähle eine der folgenden:

  • The program displays long followed by 5.

  • The program displays int 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 78 von 200

1

Which statement is false?

Wähle eine der folgenden:

  • Redeclaring a method parameter as a local variable in the method's body is a compilation error.

  • Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.

  • Forgetting to return a value from a method that should return a value is a compilation error.

  • If a method does not return a value, the return-value-type in the method declaration can be omitted.

Erklärung

Frage 79 von 200

1

What is Math.ceil(3.6)?

Wähle eine der folgenden:

  • 5.0

  • 3.0

  • 4.0

  • 3

Erklärung

Frage 80 von 200

1

Programs designed for maintainability are constructed from small simple pieces or modules. Modules in Java are called:

Wähle eine der folgenden:

  • both methods and classes.

  • arguments.

  • classes.

  • methods.

Erklärung

Frage 81 von 200

1

Which of the following promotions of primitive types is not allowed to occur?

Wähle eine der folgenden:

  • char to int.

  • int to double.

  • short to long.

  • double to float.

Erklärung

Frage 82 von 200

1

What is Math.rint(3.6)?

Wähle eine der folgenden:

  • 4.0

  • 3.0

  • 5.0

  • 3

Erklärung

Frage 83 von 200

1

Method log takes the logarithm of its argument with respect to what base?

Wähle eine der folgenden:

  • pi

  • 2

  • e

  • 10

Erklärung

Frage 84 von 200

1

Does the return statement in the following method cause compile errors?

public static void main(String[ ] args) {
int max = 0;
if (max != 0)
System.out.println(max);
else
return;
}

Wähle eine der folgenden:

  • Yes

  • No

Erklärung

Frage 85 von 200

1

Analyze the following code.

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

public static int m(int num) {
return num;
}

public static void m(int num) {
System.out.println(num);
}
}

Wähle eine der folgenden:

  • The program runs and prints 2 once.

  • The program has a compile error because the second m method is defined, but not invoked in the main method.

  • The program has a compile error because the two methods m have the same signature.

  • The program runs and prints 2 twice.

Erklärung

Frage 86 von 200

1

Arguments to methods always appear within ________.

Wähle eine der folgenden:

  • brackets

  • quotation marks

  • curly braces

  • parentheses

Erklärung

Frage 87 von 200

1

Math static method random generates a random double value in the range from 0.0

Wähle eine der folgenden:

  • up to and including 1.0

  • up to but not including 1.0

  • up to and including 100.0

  • up to but not including 100.0

Erklärung

Frage 88 von 200

1

Which of the following primitive types is never promoted to another type?

Wähle eine der folgenden:

  • double.

  • byte.

  • boolean.

  • both double and boolean

Erklärung

Frage 89 von 200

1

Suppose your method does not return any value, which of the following keywords can be used as a return type?

Wähle eine der folgenden:

  • void

  • public

  • double

  • int

  • none of the above

Erklärung

Frage 90 von 200

1

A variable defined inside a method is referred to as ________.

Wähle eine der folgenden:

  • a block variable

  • a global variable

  • a local variable

  • a method variable

Erklärung

Frage 91 von 200

1

The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as ________. (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • method hiding

  • information hiding

  • simplifying method

  • encapsulation

Erklärung

Frage 92 von 200

1

Which of the following statements about the break statement is false?

Wähle eine der folgenden:

  • Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.

  • A break statement can only break out of an immediately enclosing while, for, do…while or switch statement.

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

  • The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.

Erklärung

Frage 93 von 200

1

Consider the classes below:

public class TestA
{
public static void main( String args[] )
{
int x = 2, y = 20, counter = 0;

for ( int j = y % x; j < 100; j += ( y / x ) )
counter++;
} // end main
} // end class TestA

public class TestB
{
public static void main(String args[])
{
int counter = 0;

for ( int j = 10; j > 0; --j )
++counter;
} // end main
} // end class TestB

Which of the following statements is true?

Wähle eine der folgenden:

  • The value of counter will be different at the end of each for loop for each class.

  • The value of j will be the same for each loop for all iterations

  • Both (a) and (b) are true.

  • Neither (a) nor (b) is true.

Erklärung

Frage 94 von 200

1

For the two code segments below:

Segment A
int q = 5;
switch( q )
{
case 1:
System.out.println( 1 );
case 2:
System.out.println( 2 );
case 3:
System.out.println( 3 );
case 4:
System.out.println( 4 );
case 5:
System.out.println( 5 );
default:
System.out.println( "default" );
} // end switch

Segment B
q = 4;
switch( q )
{
case 1:
System.out.println( 1 );
case 2:
System.out.println( 2 );
case 3:
System.out.println( 3 );
case 4:
System.out.println( 4 );
case 5:
System.out.println( 5 );
default:
System.out.println( "default" );
} // end switch

Which of the following statements is true?

Wähle eine der folgenden:

  • The output for Segment B is: ?45default

  • The output for Segment B is: ?4

  • The output for Segment A is: ?default

  • The output for Segment A is: ?5?default

Erklärung

Frage 95 von 200

1

What is sum after the following loop terminates?

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

Wähle eine der folgenden:

  • 7

  • 8

  • 5

  • 6

Erklärung

Frage 96 von 200

1

The control variable of a counter-controlled loop should be declared as ________to prevent errors.

Wähle eine der folgenden:

  • double.

  • Any of the above.

  • int.

  • float.

Erklärung

Frage 97 von 200

1

Which of the following statements about a do..while repetition statement is true?

Wähle eine der folgenden:

  • The body of a do..while loop is executed only if the terminating condition is true.

  • The body of a do..while loop is executed only once.

  • The body of a do..while loop is always executed at least once.

  • None of the above

Erklärung

Frage 98 von 200

1

Which expression is equivalent to if ( ! ( grade == sentinelValue ) )?

Wähle eine der folgenden:

  • ! if ( grade == sentinelValue ).

  • ! if ( grade !== sentinelValue ).

  • if ( grade !== sentinelValue ).

  • if ( grade != sentinelValue ).

Erklärung

Frage 99 von 200

1

Which of the following assignment statements is correct to assign character 5 to c?

Wähle eine der folgenden:

  • char c = '5';

  • char c = 5;

  • char c = "5";

  • char c = "344";

Erklärung

Frage 100 von 200

1

Analyze the following code:

int i = 3434; double d = 3434;
System.out.printf("%5.1f %5.1f", i, d);

Wähle eine der folgenden:

  • The code compiles and runs fine to display 3434.0 3434.0.

  • The code compiles and runs fine to display 3434 3434.0.

  • i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.

Erklärung

Frage 101 von 200

1

What is "Welcome" + 1 + 1 * 2?

Wähle eine der folgenden:

  • Welcome11*2

  • Welcome4

  • Welcome12

  • Welcome3

Erklärung

Frage 102 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 103 von 200

1

________ returns true.

Wähle eine oder mehr der folgenden:

  • "peter".compareToIgnoreCase("Peter")

  • "peter".compareToIgnoreCase("peter")

  • "peter".equalsIgnoreCase("Peter")

  • "peter".equalsIgnoreCase("peter")

  • "peter".equals("peter")

Erklärung

Frage 104 von 200

1

To concatenate s1, s2, s3, and s4, you write ________.

Wähle eine oder mehr der folgenden:

  • s1.concate(s2).concate(s3).concate(s4);

  • s1.concate(s2) + s3.concate(s4);

  • ((s1.concate(s2)).concate(s3)).concate(s4);

  • s1.concate(s2).(concate(s3).concate(s4));

Erklärung

Frage 105 von 200

1

Assume that the ASCII code for character c is 99. 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 106 von 200

1

Math.sin(Math.PI) returns ________.

Wähle eine der folgenden:

  • 0.0

  • 1.0

  • 0.5

  • 0.4

Erklärung

Frage 107 von 200

1

parseDouble is a method in the ________ class.

Wähle eine der folgenden:

  • Integer

  • Double

  • Math

  • System

Erklärung

Frage 108 von 200

1

Is 'a' larger than 'A'?

Wähle eine der folgenden:

  • Yes

  • No

Erklärung

Frage 109 von 200

1

The order of the precedence (from high to low) of the operators +, *, &&, ||, & is:

Wähle eine der folgenden:

  • *, +, &, &&, ||

  • *, +, &, ||, &&

  • *, +, &&, ||, &

  • &, ||, &&, *, +

  • &&, ||, &, *, +

Erklärung

Frage 110 von 200

1

Analyze the following code:

if (x < 100) && (x > 10)
System.out.println("x is between 10 and 100");

Wähle eine der folgenden:

  • The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses.

  • The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses and the println(…) statement must be put inside a block.

  • The statement compiles fine.

  • The statement compiles fine, but has a runtime error.

Erklärung

Frage 111 von 200

1

The following code displays ________.

double temperature = 50;

if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
else
System.out.println("just right");

Wähle eine der folgenden:

  • too hot

  • too hot too cold just right

  • just right

  • too cold

Erklärung

Frage 112 von 200

1

To check whether a char variable ch is an uppercase letter, you write ________.

Wähle eine der folgenden:

  • ('A' <= ch <= 'Z')

  • (ch >= 'A' && ch <= 'Z')

  • (ch >= 'A' || ch <= 'Z')

  • (ch >= 'A' && ch >= 'Z')

Erklärung

Frage 113 von 200

1

The statement System.out.printf("%10s", 123456) outputs ________. (Note: * represents a space)

Wähle eine der folgenden:

  • ****123456

  • 23456*****

  • 12345*****

  • 123456****

Erklärung

Frage 114 von 200

1

The equal comparison operator in Java is ________.

Wähle eine der folgenden:

  • <>

  • ==

  • !=

  • ^=

Erklärung

Frage 115 von 200

1

To improve readability and maintainability, you should declare ________ instead of using literal values such as 3.14159.

Wähle eine der folgenden:

  • classes

  • variables

  • methods

  • constants

Erklärung

Frage 116 von 200

1

To assign a value 1 to variable x, you write

Wähle eine der folgenden:

  • 1 = x;

  • x = 1;

  • x := 1;

  • x == 1;

  • 1 := x;

Erklärung

Frage 117 von 200

1

The ________ method parses a string s to an int value.

Wähle eine der folgenden:

  • integer.parseInteger(s);

  • Integer.parseInt(s);

  • integer.parseInt(s);

  • Integer.parseInteger(s);

Erklärung

Frage 118 von 200

1

Will System.out.println((char)4) display 4?

Wähle eine der folgenden:

  • No

  • Yes

Erklärung

Frage 119 von 200

1

What is the printout of the following code:

double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);

Wähle eine der folgenden:

  • x is 5 and y is 6

  • x is 5.5 and y is 5

  • x is 6 and y is 6

  • x is 5.5 and y is 5.0

  • x is 6.0 and y is 6.0

Erklärung

Frage 120 von 200

1

What is y displayed in the following code?

public class Test1 {
public static void main(String[ ] args) {
int x = 1;
int y = x = x + 1;
System.out.println("y is " + y);
}
}

Wähle eine der folgenden:

  • y is 0.

  • The program has a compile error since x is redeclared in the statement int y = x = x + 1.

  • y is 2 because x + 1 is assigned to x and then x is assigned to y.

  • y is 1 because x is assigned to y first.

Erklärung

Frage 121 von 200

1

24 % 5 is ________.

Wähle eine der folgenden:

  • 1

  • 3

  • 2

  • 0

  • 4

Erklärung

Frage 122 von 200

1

Which of the following statements is correct to display Welcome to Java on the console? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • System.out.println("Welcome to Java");

  • System.println('Welcome to Java');

  • System.out.print('Welcome to Java');

  • System.out.println('Welcome to Java');

  • System.out.print("Welcome to Java");

Erklärung

Frage 123 von 200

1

Why do computers use zeros and ones?

Wähle eine der folgenden:

  • because combinations of zeros and ones can represent any numbers and characters.

  • because binary numbers are the bases upon which all other number systems are built.

  • because binary numbers are simplest.

  • because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.

Erklärung

Frage 124 von 200

1

Every statement in Java ends with ________.

Wähle eine der folgenden:

  • a semicolon (;)

  • a period (.)

  • an asterisk (*)

  • a comma (,)

Erklärung

Frage 125 von 200

1

________ are instructions to the computer. (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • Programs

  • Software

  • Keyboards

  • Hardware

Erklärung

Frage 126 von 200

1

________ is the physical aspect of the computer that can be seen.

Wähle eine der folgenden:

  • Software

  • Application program

  • Operating system

  • Hardware

Erklärung

Frage 127 von 200

1

The extension name of a Java source code file is

Wähle eine der folgenden:

  • .class

  • .obj

  • .java

  • .exe

Erklärung

Frage 128 von 200

1

________ is a program that runs on a computer to manage and control a computer's activities.

Wähle eine der folgenden:

  • Modem

  • Java

  • Operating system

  • Compiler

  • Interpreter

Erklärung

Frage 129 von 200

1

________ translates high-level language program into machine language program.

Wähle eine der folgenden:

  • A compiler

  • The operating system

  • CPU

  • An assembler

Erklärung

Frage 130 von 200

1

Which of the following are storage devices? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • hard disk

  • floppy disk

  • CD-ROM

  • flash stick

Erklärung

Frage 131 von 200

1

The ________ method displays a message dialog box. (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • JOptionPane.showMessage(null, "Welcome to Java!", "Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE);

  • JOptionPane.displayMessageDialog(null, "Welcome to Java!", "Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE);

  • JOptionPane.showMessageDialog(null, "Welcome to Java!", "Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE);

  • JOptionPane.showMessageDialog(null, "Welcome to Java!");

  • JOptionPane.displayMessage(null, "Welcome to Java!", "Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE);

Erklärung

Frage 132 von 200

1

What is y displayed in the following code?

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

Wähle eine der folgenden:

  • y is 4.

  • y is 1.

  • y is 3.

  • y is 2.

Erklärung

Frage 133 von 200

1

Which of the following is a constant, according to Java naming conventions? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • ReadInt

  • Test

  • MAX_VALUE

  • read

  • COUNT

Erklärung

Frage 134 von 200

1

Suppose a Scanner object is created as follows:

Scanner input = new Scanner(System.in);

What method do you use to read an int value?

Wähle eine der folgenden:

  • input.nextInt();

  • input.int();

  • input.nextInteger();

  • input.integer();

Erklärung

Frage 135 von 200

1

The System.currentTimeMillis() returns ________.

Wähle eine der folgenden:

  • the current time

  • the current time in milliseconds since midnight, January 1, 1970

  • the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)

  • the current time in milliseconds

  • the current time in milliseconds since midnight

Erklärung

Frage 136 von 200

1

The Unicode of 'a' is 97. What is the Unicode for 'c'?

Wähle eine der folgenden:

  • 96

  • 97

  • 99

  • 98

Erklärung

Frage 137 von 200

1

________ is the Java assignment operator.

Wähle eine der folgenden:

  • :=

  • ==

  • =:

  • =

Erklärung

Frage 138 von 200

1

The statement System.out.printf("%5d", 123456) outputs ________.

Wähle eine der folgenden:

  • 12345.6

  • 23456

  • 123456

  • 12345

Erklärung

Frage 139 von 200

1

Which of the Boolean expressions below is incorrect? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • (-10 < x < 0)

  • (true) && (3 => 4)

  • (x != 0) || (x = 0)

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

  • !(x > 0) && (x > 0)

Erklärung

Frage 140 von 200

1

"ab".compareTo("aB") is ________.

Wähle eine der folgenden:

  • greater than 0

  • less than 0

  • equal to 0

  • less than or equal to 0

Erklärung

Frage 141 von 200

1

"smiles".substring(1, 5) returns "mile".

Wähle eine der folgenden:

  • true

  • false

Erklärung

Frage 142 von 200

1

Which of the following is a possible output for (int)(51 * Math.random())?

Wähle eine oder mehr der folgenden:

  • 0

  • 50

  • 100

  • 500

Erklärung

Frage 143 von 200

1

Which of the following statement prints smith\exam1\test.txt?

Wähle eine der folgenden:

  • System.out.println("smith\exam1\test.txt");

  • System.out.println("smith\\exam1\\test.txt");

  • System.out.println("smith\"exam1\"test.txt");

  • System.out.println("smith"\exam1"\test.txt");

Erklärung

Frage 144 von 200

1

Math.sqrt(4) returns ________.

Wähle eine der folgenden:

  • 2

  • 2.0

  • 1

  • 1.0

Erklärung

Frage 145 von 200

1

'3' - '2' + 'm' / 'n' is ________.

Wähle eine der folgenden:

  • 0

  • 1

  • 2

  • 3

Erklärung

Frage 146 von 200

1

An int variable can hold ________.

Wähle eine oder mehr der folgenden:

  • 'x'

  • 120

  • 120.0

Erklärung

Frage 147 von 200

1

Analyze the following fragment:

double sum = 0;
double d = 0;
while (d != 10.0) {
d += 0.1;
sum += sum + d;
}

Wähle eine der folgenden:

  • After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9

  • The program does not compile because sum and d are declared double, but assigned with integer value 0.

  • The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.

  • The program never stops because d is always 0.1 inside the loop.

Erklärung

Frage 148 von 200

1

After the continue outer statement is executed in the following loop, which statement is executed?

outer:
for (int i = 1; i < 10; i++) {
inner:
for (int j = 1; j < 10; j++) {
if (i * j > 50)
continue outer;
System.out.println(i * j);
}
}
next:

Wähle eine der folgenden:

  • The control is in the outer loop, and the next iteration of the outer loop is executed.

  • The program terminates.

  • The statement labeled next.

  • The control is in the inner loop, and the next iteration of the inner loop is executed.

Erklärung

Frage 149 von 200

1

Consider the following two Java code segments:

Segment 1
int i = 0;
for ( int i = 0; i <= 20; i++ ) {

System.out.println( i );
}

Segment 2
while ( i < 20 )
{

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

}

Which of the following statements are true?

Wähle eine der folgenden:

  • The output from these segments is not the same.

  • The scope of the control variable i is different for the two segments.

  • They are both true

  • Neither are true

Erklärung

Frage 150 von 200

1

Which statement prints the floating-point value 123.456 right justified with a field width of 10?

Wähle eine der folgenden:

  • System.out.printf( “%10.3f”, 123.456 );

  • System.out.printf( “%f10.3”, 123.456 );

  • System.out.printf( “%d10.3”, 123.456 );

  • System.out.printf( “%10.3d”, 123.456 );

Erklärung

Frage 151 von 200

1

Which statement below is not true?

Wähle eine der folgenden:

  • Structured programming produces programs that are easier to modify

  • Structured programming produces programs that are easier to test.

  • Structured programming promotes simplicity.

  • Structured programming requires four forms of control.

Erklärung

Frage 152 von 200

1

An enumeration is a special class that is introduced by the keyword ________ and a type name.

Wähle eine der folgenden:

  • class.

  • classEnum.

  • enumeration.

  • enum.

Erklärung

Frage 153 von 200

1

When an object is concatenated with a String:

Wähle eine der folgenden:

  • a compilation error occurs.

  • the object's class name is used.

  • the object's toString method is implicitly called to obtain the String representation of the object.

  • a runtime error occurs.

Erklärung

Frage 154 von 200

1

Suppose method1 is declared as

void method1 ( int a, float b )

Which of the following methods correctly overloads method1?

Wähle eine der folgenden:

  • void method2 ( int a, float b ).

  • void method2 ( float a, int b ).

  • void method1 ( float a, int b ).

  • void method1 ( int b, float a ).

Erklärung

Frage 155 von 200

1

Which operator can be used in string concatenation?

Wähle eine der folgenden:

  • ++.

  • +=.

  • =+.

  • *.

Erklärung

Frage 156 von 200

1

(char)('a' + Math.random() * ('z' - 'a' + 1)) returns a random character ________.

Wähle eine der folgenden:

  • between 'a' and 'z'

  • between 'b' and 'z'

  • between 'a' and 'y'

  • between 'b' and 'y'

Erklärung

Frage 157 von 200

1

Which of the following is the best for generating random integer 0 or 1?

Wähle eine der folgenden:

  • (int)(Math.random() + 0.2)

  • (int)Math.random()

  • (int)Math.random() + 1

  • (int)(Math.random() + 0.8)

  • (int)(Math.random() + 0.5)

Erklärung

Frage 158 von 200

1

Information is passed to a method in:

Wähle eine der folgenden:

  • the method body.

  • the method name.

  • the arguments to the method.

  • that method's return.

Erklärung

Frage 159 von 200

1

The signature of a method consists of ________.

Wähle eine der folgenden:

  • method name

  • method name and parameter list

  • return type, method name, and parameter list

  • parameter list

Erklärung

Frage 160 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
int[ ] a = new int[4];
a[1] = 1;
a = new int[2];
System.out.println("a[1] is " + a[1]);
}
}

Wähle eine der folgenden:

  • The program displays a[1] is 1.

  • The program has a runtime error because a[1] is not initialized.

  • The program displays a[1] is 0.

  • The program has a compile error because new int[2] is assigned to a.

Erklärung

Frage 161 von 200

1

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

Wähle eine oder mehr der folgenden:

  • public static void print(double... numbers)

  • public static double... print(double d1, double d2)

  • public static void print(double... numbers, String name)

  • public static void print(String... strings, double... numbers)

  • public static void print(int n, double... numbers)

Erklärung

Frage 162 von 200

1

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

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

Wähle eine der folgenden:

  • list1 is 6 6 6 6 6 6

  • list1 is 0 0 0 0 0 0

  • list1 is 1 2 3 4 5 6

  • list1 is 6 5 4 3 2 1

Erklärung

Frage 163 von 200

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
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 1 2 3 4

  • The program displays 0 0 0 0

  • The program displays 0 0

  • The program displays 0 0 3 4

Erklärung

Frage 164 von 200

1

Suppose int i = 5, which of the following can be used as an index for array double[ ] t = new double[100]? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • (int)(Math.random() * 100))

  • Math.random() * 100

  • i

  • i + 6.5

  • i + 10

Erklärung

Frage 165 von 200

1

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

Wähle eine der folgenden:

  • 4

  • 2

  • 3

  • 0

  • 1

Erklärung

Frage 166 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 int[ ]{1, 2, 3};

  • return {1, 2, 3};

  • return 1;

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

Erklärung

Frage 167 von 200

1

Analyze the following code:

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:

  • The program displays 1 2 3 4 5.

  • The program displays 1 2 3 4 5 and then raises an ArrayIndexOutOfBoundsException.

  • The program displays 5 4 3 2 1.

  • The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException.

Erklärung

Frage 168 von 200

1

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

public class Test {
public static void main(String[ ] args) {
A a = new A();
a.print();
}
}

class A {
String s;

A(String s) {
this.s = s;
}

void print() {
System.out.println(s);
}
}

Wähle eine oder mehr der folgenden:

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

  • The program would compile and run if you change A a = new A() to A a = new A("5").

  • The program compiles and runs fine and prints nothing.

  • The program has a compilation error because class A is not a public class.

Erklärung

Frage 169 von 200

1

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

Wähle eine oder mehr der folgenden:

  • Data fields have default values.

  • You may assign an int value to a reference variable.

  • Local variables do not have default values.

  • A variable of a reference type holds a reference to where an object is stored in the memory.

  • A variable of a primitive type holds a value of the primitive type.

Erklärung

Frage 170 von 200

1

Given the declaration Circle x = new Circle(), which of the following statement is most accurate?

Wähle eine der folgenden:

  • You can assign an int value to x.

  • x contains a reference to a Circle object.

  • x contains an int value.

  • x contains an object of the Circle type.

Erklärung

Frage 171 von 200

1

The keyword ________ is required to declare a class.

Wähle eine der folgenden:

  • private

  • class

  • All of the above.

  • public

Erklärung

Frage 172 von 200

1

In this question, assume a class, Book, has been defined. Which set of statements creates an array of Book objects?

Wähle eine der folgenden:

  • Book[] books;

    books = new Book()[ numberElements ];

  • Book[] books;

    books = new Book[ numberElements ];

  • All of the above.

  • new Book() books[];

    books = new Book[ numberElements ];

Erklärung

Frage 173 von 200

1

What is wrong in the following code?

class TempClass {
int i;
public void TempClass(int j) {
int i = j;
}
}

public class C {
public static void main(String[ ] args) {
TempClass temp = new TempClass(2);
}
}

Wähle eine der folgenden:

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

  • The program has a compilation error because TempClass does not have a constructor with an int argument.

  • The program compiles fine, but it does not run because class C is not public.

  • The program compiles and runs fine.

Erklärung

Frage 174 von 200

1

What is the default initial value of a String instance variable?

Wähle eine der folgenden:

  • "default"

  • ""

  • null

  • default

Erklärung

Frage 175 von 200

1

You should add the static keyword in the place of ? in line ________ in the following code:

1 public class Test {
2 private int age;
3
4 public ? int square(int n) {
5 return n * n;
6 }
7
8 public ? int getAge() {
9 }
10}

Wähle eine der folgenden:

  • in both line 4 and line 8

  • in line 8

  • in line 4

  • none

Erklärung

Frage 176 von 200

1

The boolean values can be displayed with the ________ format specifier.

Wähle eine der folgenden:

  • %a.

  • %b.

  • %c.

  • %bool.

Erklärung

Frage 177 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

  • 2*n

  • n

  • n - 1

Erklärung

Frage 178 von 200

1

What modifier should you use on a class so that a class in the same package can access it but a class in a different package cannot access it?

Wähle eine der folgenden:

  • protected

  • private

  • public

  • Use the default modifier.

Erklärung

Frage 179 von 200

1

Which of the following is true?

Wähle eine der folgenden:

  • Pseudocode is used to describe an algorithm.

  • Pseudocode is translatable by the programmer into a programming language (like Java).

  • Pseudocode is used to describe executable statements that will eventually be translated by the programmer into a program.

  • All of the above.

Erklärung

Frage 180 von 200

1

Which of the following is a double-selection control statement?

Wähle eine der folgenden:

  • do..while.

  • for.

  • if...else.

  • if.

Erklärung

Frage 181 von 200

1

Suppose s1 and s2 are two strings. What is the result of the following code?

s1.equals(s2) == s2.equals(s1)

Wähle eine der folgenden:

  • true

  • false

Erklärung

Frage 182 von 200

1

A class within a package must be declared public if

Wähle eine der folgenden:

  • It will be used only by other classes in the same package.

  • It will be used by classes that are not in the same package.

  • It is in the same directory as the other classes in the package.

  • It has a unique name.

Erklärung

Frage 183 von 200

1

A String constructor cannot be passed variables of type:

Wähle eine der folgenden:

  • char arrays.

  • int arrays.

  • byte arrays.

  • Strings.

Erklärung

Frage 184 von 200

1

A programmer-defined constructor that has no arguments is called a ________.

Wähle eine der folgenden:

  • zero-argument constructor.

  • no-argument constructor.

  • default constructor.

  • main constructor.

Erklärung

Frage 185 von 200

1

Is the following loop correct?

for (; ; );

Wähle eine der folgenden:

  • Yes

  • No

Erklärung

Frage 186 von 200

1

You can create an ArrayList using ________.

Wähle eine der folgenden:

  • ArrayList()

  • new ArrayList()

  • new ArrayList[100]

  • new ArrayList[ ]

Erklärung

Frage 187 von 200

1

List the following operators in the order that they will be evaluated: -, *, /, +, %. Assume that if two operations have the same precedence, the one listed first will be evaluated first.

Wähle eine der folgenden:

  • +, -, /, *, %.

  • -, +, %, *, /.

  • -, *, %, +, /.

  • *, /, %, -, +.

Erklärung

Frage 188 von 200

1

Which of the following is not a Java primitive type?

Wähle eine der folgenden:

  • char

  • byte

  • real

  • double

Erklärung

Frage 189 von 200

1

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

Wähle eine oder mehr der folgenden:

  • The nextInt() method in the Random class returns the next random int value.

  • The nextDouble() method in the Random class returns the next random double value.

  • When creating a Random object, you have to specify the seed or use the default seed.

  • If two Random objects have the same seed, the sequence of the random numbers obtained from these two objects are identical.

Erklärung

Frage 190 von 200

1

What exception type does the following program throw?

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

Wähle eine der folgenden:

  • ClassCastException

  • No exception

  • ArrayIndexOutOfBoundsException

  • ArithmeticException

  • StringIndexOutOfBoundsException

Erklärung

Frage 191 von 200

1

Which of the following is not a benefit of goto-less programming?

Wähle eine der folgenden:

  • Easier to debug and modify

  • Shorter

  • Clearer

  • More likely to be bug free

Erklärung

Frage 192 von 200

1

Consider integer array values, which contains 5 elements. Which statements successfully swap the contents of the array at index 3 and index 4?

Wähle eine der folgenden:

  • values[ 3 ] = values[ 4 ];

    values[ 4 ] = values[ 3 ];

  • values[ 4 ] = values[ 3 ];

    values[ 3 ] = values[ 4 ];

  • int temp = values[ 3 ];

    values[ 3 ] = values[ 4 ];

    values[ 4 ] = temp;

  • int temp = values[ 3 ];

    values[ 3 ] = values[ 4 ];

    values[ 4 ] = values[ 3 ];

Erklärung

Frage 193 von 200

1

To prevent a class from being instantiated, ________

Wähle eine der folgenden:

  • use the static modifier on the constructor.

  • use the public modifier on the constructor.

  • don't use any modifiers on the constructor.

  • use the private modifier on the constructor.

Erklärung

Frage 194 von 200

1

When compiling a class in a package, the javac command-line option ________ causes the javac compiler to create appropriate directories based on the class's package declaration.

Wähle eine der folgenden:

  • -p.

  • -a.

  • -d.

  • -dir.

Erklärung

Frage 195 von 200

1

An advantage of inheritance is that:

Wähle eine der folgenden:

  • All methods can be inherited.

  • All instance variables can be uniformly accessed by subclasses and superclasses.

  • Objects of a subclass can be treated like objects of their superclass.

  • None of the above.

Erklärung

Frage 196 von 200

1

An instance of ________ are unchecked exceptions. (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • Throwable

  • NumberFormatException

  • Error

  • Exception

  • RuntimeException

Erklärung

Frage 197 von 200

1

Assume StringBuilder strBuf is "ABCCEFC", after invoking ________, strBuf contains "ABTTEFT".

Wähle eine der folgenden:

  • strBuf.replace(2, 7, "TTEFT")

  • strBuf.replace("CC", "TT")

  • strBuf.replace("C", "T")

  • strBuf.replace('C', "TT")

  • strBuf.replace('C', 'T')

Erklärung

Frage 198 von 200

1

Using public set methods provides data integrity if:

Wähle eine der folgenden:

  • The instance variables are public.

  • The instance variables are private.

  • The methods perform validity checking.

  • Both b and c.

Erklärung

Frage 199 von 200

1

Which of the following is the correct header of the main method? (Choose all that apply.)

Wähle eine oder mehr der folgenden:

  • public static void main(String[ ] x)

  • public static void main(String args[ ])

  • static void main(String[ ] args)

  • public static void main(String x[ ])

  • public static void main(String[ ] args)

Erklärung

Frage 200 von 200

1

What is x after the following statements?

int x = 1;
int y = 2;
x *= y + 1;

Wähle eine der folgenden:

  • x is 2.

  • x is 3.

  • x is 1.

  • x is 4.

Erklärung