Ummm No
Test por , creado hace más de 1 año

A practice test for Java level 1 at Gwinnett Technical College

247
1
0
Ummm No
Creado por Ummm No hace casi 9 años
Cerrar

Java Practice 3

Pregunta 1 de 105

1

Which class do you use to write data into a text file?

Selecciona una de las siguientes respuestas posibles:

  • System

  • PrintWriter

  • Scanner

  • File

Explicación

Pregunta 2 de 105

1

Which of the following statements is false?

Selecciona una de las siguientes respuestas posibles:

  • The smallest data item a computer can assume is the value 0 or the value 1.

  • The term "bit" is short for "byte digit."

  • Java uses the Unicode character set.

  • A record is typically composed of several fields.

Explicación

Pregunta 3 de 105

1

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

Selecciona una de las siguientes respuestas posibles:

  • "SELECT"

  • "SELE"

  • "SELEC"

  • "ELECT"

Explicación

Pregunta 4 de 105

1

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

Selecciona una o más de las siguientes respuestas posibles:

  • i == j == k == 1;

  • i = j = k = 1;

  • i = 1; j = 1; k = 1;

  • i = 1 = j = 1 = k = 1;

Explicación

Pregunta 5 de 105

1

An argument type followed by a(n) __________________ in a method's parameter list indicates that the method receives a variable number of arguments of that particular type.

Selecciona una de las siguientes respuestas posibles:

  • square brackets ([]).

  • ellipsis ().

  • varargs keyword.

  • All of the above are acceptable to indicate a variable number of arguments.

Explicación

Pregunta 6 de 105

1

Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 element, the second row contains 4 elements and the final row contains 2 elements?

Selecciona una de las siguientes respuestas posibles:

  • int[][] items = { { 1, null, null, null }, { 2, 3, 4, 5 }, { 6, 7, null, null } };.

  • int[][] items = { { 1 }, { 2, 3, 4, 5 }, { 6, 7 } };.

  • int[][] items = { { 1 }, { 2, 3, 4, 5 }, { 6, 7 }, {} );.

  • int[][] items = { { 1 }, { 4 }, { 2 } };.

Explicación

Pregunta 7 de 105

1

What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package?

Selecciona una de las siguientes respuestas posibles:

  • protected

  • public

  • private

  • Use the default modifier.

Explicación

Pregunta 8 de 105

1

Which of the following statements are true about an immutable object? (Choose all that apply.)

Selecciona una o más de las siguientes respuestas posibles:

  • The contents of an immutable object cannot be modified.

  • An immutable object contains no mutator methods.

  • All properties of an immutable object must be of primitive types.

  • All properties of an immutable object must be private.

  • An object type property in an immutable object must also be immutable.

Explicación

Pregunta 9 de 105

1

What is the output of the following code?
public class Test {
public static void main(String[ ] args) {
String s1 = new String("Welcome to Java");
String s2 = s1;

s1 += "and Welcome to HTML";

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}

Selecciona una de las siguientes respuestas posibles:

  • s1 and s2 reference to different String objects

  • s1 and s2 reference to the same String object

Explicación

Pregunta 10 de 105

1

Which of the following is not an algorithm?

Selecciona una de las siguientes respuestas posibles:

  • A recipe.

  • Operating instructions.

  • Textbook index.

  • Shampoo instructions (lather, rinse, repeat).

Explicación

Pregunta 11 de 105

1

Which of the following segments is a proper way to call the method readData four times?

Selecciona una de las siguientes respuestas posibles:

  • double k;

    k = 0.0;


    while (k != 4) 
{

    readData();

    k = k + 1;

    } // end while

  • int i;

    i = 0;


    while ( i <= 4 ) 
{

    readData();

    i = i + 1;

    } // end while

  • int i;

    i = 0;


    while ( i < 4 ) 
{

    readData();

    } // end while

  • int i;

    i = 0;


    while ( i < 4 ) 
{
    readData();

    i = i + 1;

    } // end while

Explicación

Pregunta 12 de 105

1

Which method returns an array of the enum’s constants?

Selecciona una de las siguientes respuestas posibles:

  • values.

  • getValues.

  • constants.

  • getConstants.

Explicación

Pregunta 13 de 105

1

An anonymous String:

Selecciona una de las siguientes respuestas posibles:

  • has no value.

  • is a string literal.

  • can be changed.

  • none of the above.

Explicación

Pregunta 14 de 105

1

What exception type does the following program throw?

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

Selecciona una de las siguientes respuestas posibles:

  • StringIndexOutOfBoundsException

  • NullPointerException

  • ArrayIndexOutOfBoundsException

  • No exception

  • ArithmeticException

Explicación

Pregunta 15 de 105

1

Overloaded methods always have the same _________.

Selecciona una de las siguientes respuestas posibles:

  • method name.

  • return type.

  • number of parameters.

  • order of the parameters.

Explicación

Pregunta 16 de 105

1

All import declarations must be placed

Selecciona una de las siguientes respuestas posibles:

  • inside the class declaration’s body.

  • before the class declaration.

  • after the class declaration.

  • all of the above will work.

Explicación

Pregunta 17 de 105

1

The preferred way to traverse a two-dimensional array is to use _______ .

Selecciona una de las siguientes respuestas posibles:

  • a do while statement.

  • a for statement.

  • two nested for statements.

  • three nested for statements.

Explicación

Pregunta 18 de 105

1

Which of the following will count down from 10 to 1 correctly?

Selecciona una de las siguientes respuestas posibles:

  • for ( int j = 10; j <= 1; j++ )

  • for ( int j = 1; j <= 10; j++ )

  • for ( int j = 10; j > 1; j-- )

  • for ( int j = 10; j >= 1; j-- )

Explicación

Pregunta 19 de 105

1

Which of the following does not contribute to improved software reusability?

Selecciona una de las siguientes respuestas posibles:

  • Quickly creating new class libraries without testing them thoroughly.

  • Licensing schemes and protection mechanisms.

  • Descriptions of classes that allow programmers to determine whether a class fits their needs.

  • Cataloging schemes and browsing mechanisms.

Explicación

Pregunta 20 de 105

1

What code may be filled in the blank without causing syntax or runtime errors:

public class Test {
java.util.Date date;

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

Selecciona una de las siguientes respuestas posibles:

  • date

  • test.date

  • date.toString()

  • test.date.toString()

Explicación

Pregunta 21 de 105

1

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

Selecciona una o más de las siguientes respuestas posibles:

  • class

  • radius

  • 9X

  • 8+9

  • $343

Explicación

Pregunta 22 de 105

1

When should a program explicitly use the this reference?

Selecciona una de las siguientes respuestas posibles:

  • Accessing a private variable.

  • Accessing a public variable.

  • Accessing a local variable.

  • Accessing a field that is shadowed by a local variable.

Explicación

Pregunta 23 de 105

1

Variables that are shared by every instances of a class are ________.

Selecciona una de las siguientes respuestas posibles:

  • class variables

  • public variables

  • private variables

  • instance variables

Explicación

Pregunta 24 de 105

1

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

Selecciona una o más de las siguientes respuestas posibles:

  • The capacity of a string buffer can be automatically adjusted.

  • You can reverse the characters in a string buffer.

  • You can add characters into a string buffer.

  • You can delete characters into a string buffer.

Explicación

Pregunta 25 de 105

1

Which of the following is arranged in increasing size order?

Selecciona una de las siguientes respuestas posibles:

  • field, bit, file, record.

  • byte, file, database, record.

  • byte, field, file, record.

  • bit, field, record, file.

Explicación

Pregunta 26 de 105

1

Which method can be used to read a whole line from the file?

Selecciona una de las siguientes respuestas posibles:

  • nextInt

  • next

  • nextLine

  • nextDouble

Explicación

Pregunta 27 de 105

1

-24 % -5 is ________.

Selecciona una de las siguientes respuestas posibles:

  • 3

  • -3

  • 4

  • -4

  • 0

Explicación

Pregunta 28 de 105

1

Analyze the following code.

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

Selecciona una de las siguientes respuestas posibles:

  • The program displays month is 9.0

  • The program displays month is 9

  • The program displays month is 09

  • The program has a syntax error, because 09 is an incorrect literal value.

Explicación

Pregunta 29 de 105

1

A decision symbol in an activity diagram takes the shape of a ________.

Selecciona una de las siguientes respuestas posibles:

  • Diamond.

  • Rectangle.

  • Circle.

  • Triangle.

Explicación

Pregunta 30 de 105

1

Analyze the following code.

// Program 1:
public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}

class A {
int x;

public boolean equals(Object a) {
return this.x == ((A)a)x;
}
}

// Program 2:
public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}

class A {
int x;

public boolean equals(A a) {
return this.x == a.x;
}
}

Selecciona una de las siguientes respuestas posibles:

  • Program 1 displays true and Program 2 displays true

  • Program 1 displays true and Program 2 displays false

  • Program 1 displays false and Program 2 displays true

  • Program 1 displays false and Program 2 displays false

Explicación

Pregunta 31 de 105

1

Which correctly creates an array of five empty Strings?

Selecciona una de las siguientes respuestas posibles:

  • String[ ] a = new String [5];

  • String[ ] a = new String [5]; for (int i = 0; i < 5; a[i++] = null);

  • String[ ] a = {"", "", "", "", ""};

  • String[5] a;

Explicación

Pregunta 32 de 105

1

Which of the following are Java keywords?

Selecciona una de las siguientes respuestas posibles:

  • instanceof

  • instanceOf

  • casting

  • cast

Explicación

Pregunta 33 de 105

1

When you return an array from a method, the method returns ________.

Selecciona una de las siguientes respuestas posibles:

  • a copy of the array

  • the reference of the array

  • a copy of the first element

  • the length of the array

Explicación

Pregunta 34 de 105

1

What is the output of the following code?

public class Test {
public static void main(String[ ] args) {
String s1 = new String("Welcome to Java!");
String s2 = new String("Welcome to Java!");

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}

Selecciona una de las siguientes respuestas posibles:

  • s1 and s2 reference to different String objects

  • s1 and s2 reference to the same String object

Explicación

Pregunta 35 de 105

1

Which of the following should usually be private?

Selecciona una de las siguientes respuestas posibles:

  • Methods.

  • Constructors.

  • Variables (or fields).

  • All of the above.

Explicación

Pregunta 36 de 105

1

When an argument is passed by reference:

Selecciona una de las siguientes respuestas posibles:

  • a copy of the argument’s value is passed to the called method.

  • changes to the argument do not affect the original variable’s value in the caller.

  • the called method can access the argument’s value in the caller directly and modify that data.

  • the original value is removed from memory.

Explicación

Pregunta 37 de 105

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);

Selecciona una de las siguientes respuestas posibles:

  • 10

  • 8

  • 0

  • 9

  • 11

Explicación

Pregunta 38 de 105

1

Suppose TestCircle and Circle in Listing 7.1 in the textbook are in two separate files named TestCircle.java and Circle.java, respectively. What is the outcome of compiling TestCircle.java and then Circle.java?

Selecciona una de las siguientes respuestas posibles:

  • Only TestCircle.java compiles.

  • Both compile fine.

  • Neither compiles successfully.

  • Only Circle.java compiles.

Explicación

Pregunta 39 de 105

1

The default value for data field of a boolean type, numeric type, object type is ________, respectively.

Selecciona una de las siguientes respuestas posibles:

  • true, 1, Null

  • true, 1, null

  • false, 0, null

  • false, 1, null

  • true, 0, null

Explicación

Pregunta 40 de 105

1

Which of the following is not a valid Java identifier?

Selecciona una de las siguientes respuestas posibles:

  • my Value

  • $_AAA1

  • width

  • m_x

Explicación

Pregunta 41 de 105

1

Consider the array:

s[ 0 ] = 7

s[ 1 ] = 0

s[ 2 ] = -12

s[ 3 ] = 9

s[ 4 ] = 10

s[ 5 ] = 3

s[ 6 ] = 6

The value of s[ s[ 6 ] - s[ 5 ] ] is

Selecciona una de las siguientes respuestas posibles:

  • 0

  • 3

  • 9

Explicación

Pregunta 42 de 105

1

Which of the following is not a superclass/subclass relationship?

Selecciona una de las siguientes respuestas posibles:

  • Ford/Taurus.

  • University/Brown University.

  • Sailboat/Tugboat.

  • Country/USA.

Explicación

Pregunta 43 de 105

1

Which of the following is the shape of an action-state symbol?

Selecciona una de las siguientes respuestas posibles:

  • Diamond.

  • Circle.

  • Rectangle with left and right sides replaced with arcs curving outward.

  • Rounded rectangle.

Explicación

Pregunta 44 de 105

1

Analyze the following code:

public class Test1 {
public static void main(String[ ] args) {
xMethod(new double[ ]{3, 3});
xMethod(new double[5]);
xMethod(new double[3]{1, 2, 3});
}

public static void xMethod(double[ ] a) {
System.out.println(a.length);
}
}

Selecciona una de las siguientes respuestas posibles:

  • The program has a compile error because xMethod(new double[ ]{3, 3}) is incorrect.

  • The program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect.

  • The program has a compile error because xMethod(new double[5]) is incorrect.

  • The program has a runtime error because a is null.

Explicación

Pregunta 45 de 105

1

What is output by the following Java code segment?

int temp;
temp = 180;

if ( temp > 90 )
{
System.out.println( "This porridge is too hot." );

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

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

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

Selecciona una de las siguientes respuestas posibles:

  • This porridge is too hot.

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

  • This porridge is just right!

  • None of the above.

Explicación

Pregunta 46 de 105

1

A method must declare to throw ________.

Selecciona una de las siguientes respuestas posibles:

  • Error

  • unchecked exceptions

  • checked exceptions

  • RuntimeException

Explicación

Pregunta 47 de 105

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");
}

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

Selecciona una de las siguientes respuestas posibles:

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

  • 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.

  • You cannot catch RuntimeException errors.

Explicación

Pregunta 48 de 105

1

Which syntax imports all static members of class Math?

Selecciona una de las siguientes respuestas posibles:

  • static import java.lang.Math.*.

  • import static java.lang.Math.*.

  • static import java.lang.Math.

  • import static java.lang.Math.

Explicación

Pregunta 49 de 105

1

The StringBuilder methods ________ not only change the contents of a string buffer, but also returns a reference to the string buffer. (Choose all that apply.)

Selecciona una o más de las siguientes respuestas posibles:

  • delete

  • replace

  • append

  • reverse

  • insert

Explicación

Pregunta 50 de 105

1

Every letter in a Java keyword is in lowercase.

Selecciona una de las siguientes respuestas posibles:

  • true

  • false

Explicación

Pregunta 51 de 105

1

Math.pow(2, 3) returns ________.

Selecciona una de las siguientes respuestas posibles:

  • 8.0

  • 9.0

  • 8

  • 9

Explicación

Pregunta 52 de 105

1

Which of the following classes cannot be extended?

Selecciona una de las siguientes respuestas posibles:

  • class A { protected A();}

  • class A { private A();}

  • final class A { }

  • class A { }

Explicación

Pregunta 53 de 105

1

In an expression containing values of the types int and double, the ________ values are ________ to ________ values for use in the expression.

Selecciona una de las siguientes respuestas posibles:

  • int, promoted, double.

  • int, demoted, double.

  • double, promoted, int.

  • double, demoted, int.

Explicación

Pregunta 54 de 105

1

Having a this reference allows:

Selecciona una de las siguientes respuestas posibles:

  • a method to refer explicitly to the instance variables and other methods of the object on which the method was called.

  • a method to refer implicitly to the instance variables and other methods of the object on which the method was called.

  • an object to reference itself.

  • All of the above.

Explicación

Pregunta 55 de 105

1

An instance of ________ describes programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors..

Selecciona una de las siguientes respuestas posibles:

  • Exception

  • NumberFormatException

  • Error

  • RuntimeException

  • Throwable

Explicación

Pregunta 56 de 105

1

Analyze the following code.

// Program 1
public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(((A)a1).equals((A)a2));
}
}

class A {
int x;

public boolean equals(A a) {
return this.x == a.x;
}
}

// Program 2
public class Test {
public static void main(String[ ] args) {
A a1 = new A();
A a2 = new A();
System.out.println(a1.equals(a2));
}
}

class A {
int x;

public boolean equals(A a) {
return this.x == a.x;
}
}

Selecciona una de las siguientes respuestas posibles:

  • Program 1 displays false and Program 2 displays false

  • Program 1 displays true and Program 2 displays true

  • Program 1 displays true and Program 2 displays false

  • Program 1 displays false and Program 2 displays true

Explicación

Pregunta 57 de 105

1

How many significant digits does a double variable have?

Selecciona una de las siguientes respuestas posibles:

  • 7.

  • 8.

  • 14.

  • 15.

Explicación

Pregunta 58 de 105

1

In Java graphics, coordinate units are measured in ________.

Selecciona una de las siguientes respuestas posibles:

  • dots.

  • pixels.

  • points.

  • inches.

Explicación

Pregunta 59 de 105

1

Which code fragment would correctly identify the number of arguments passed via the command line to a Java application, excluding the name of the class that is being invoked?

Selecciona una de las siguientes respuestas posibles:

  • int count = 0; while (args[count] != null) count ++;

  • int count = args.length;

  • int count = args.length - 1;

  • int count=0; while (!(args[count].equals(""))) count ++;

Explicación

Pregunta 60 de 105

1

The ________ method returns a raised to the power of b.

Selecciona una de las siguientes respuestas posibles:

  • Math.pow(a, b)

  • Math.pow(b, a)

  • Math.power(a, b)

  • Math.exponent(a, b)

Explicación

Pregunta 61 de 105

1

Which of the following will not produce a compiler error?

Selecciona una de las siguientes respuestas posibles:

  • Changing the value of a constant after it is declared.

  • Changing the value at a given index of an array after it is created.

  • Using a final variable before it is initialized.

  • All of the above will produce compiler errors.

Explicación

Pregunta 62 de 105

1

The default equals implementation determines:

Selecciona una de las siguientes respuestas posibles:

  • whether two references refer to the same object in memory.

  • whether two references have the same type.

  • whether two objects have the same instance variables.

  • whether two objects have the same instance variable values.

Explicación

Pregunta 63 de 105

1

Analyze the following code:

public class Test {
public static void main(String[ ] args) {
B b = new B();
b.m(5);
System.out.println("i is " + b.i);
}
}

class A {
int i;

public void m(int i) {
this.i = i;
}
}

class B extends A {
public void m(String s) {
}
}

Selecciona una de las siguientes respuestas posibles:

  • The program has a compilation error, because m is overridden with a different signature in B.

  • The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

  • The program has a runtime error on b.i, because i is not accessible from b.

  • The program has a compilation error, because b.m(5) cannot be invoked since the method m(int) is hidden in B.

Explicación

Pregunta 64 de 105

1

What is the output of the following program?

import java.util.Date;

public class Test {
public static void main(String[ ] args) {
Date date = new Date(1234567);
m1(date);
System.out.print(date.getTime() + " ");

m2(date);
System.out.println(date.getTime());
}

public static void m1(Date date) {
date = new Date(7654321);
}

public static void m2(Date date) {
date.setTime(7654321);
}
}

Selecciona una de las siguientes respuestas posibles:

  • 7654321 1234567

  • 1234567 7654321

  • 7654321 7654321

  • 1234567 1234567

Explicación

Pregunta 65 de 105

1

Given the following method

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

What is the printout of the call nPrint('a', 4)?

Selecciona una de las siguientes respuestas posibles:

  • aaaa

  • aaa

  • invalid call

  • aaaaa

Explicación

Pregunta 66 de 105

1

Which of the following can be used in the expression after keyword case?

A. a constant integral expression.
B. a character constant.
C. a constant.
D. an enumeration constant.

Selecciona una de las siguientes respuestas posibles:

  • A and B.

  • A and C.

  • B and C.

  • All.

Explicación

Pregunta 67 de 105

1

In array items, which expression below accesses the value at row 3 and column 4?

Selecciona una de las siguientes respuestas posibles:

  • items[ 3 ].[ 4 ].

  • items[ 3[ 4 ] ].

  • items[ 3 ][ 4 ].

  • items[ 3, 4 ].

Explicación

Pregunta 68 de 105

1

Which of the following is the correct statement to return JAVA?

Selecciona una de las siguientes respuestas posibles:

  • String.toUpperCase("Java")

  • "Java".toUpperCase()

  • toUpperCase("Java")

  • "Java".toUpperCase("Java")

Explicación

Pregunta 69 de 105

1

Which statement is false?

Selecciona una de las siguientes respuestas posibles:

  • The actual data representation used within the class is of no concern to the class's clients.

  • Clients generally care about what the class does but not how the class does it.

  • Clients are usually involved in a class's implementation.

  • Hiding the implementation reduces the possibility that clients will become dependent on class-implementation details.

Explicación

Pregunta 70 de 105

1

Which of the following is not an arithmetic operator?

Selecciona una de las siguientes respuestas posibles:

  • +

  • -

  • .

  • %

Explicación

Pregunta 71 de 105

1

Which of the following classes is not used for file input?

Selecciona una de las siguientes respuestas posibles:

  • FileInputStream

  • FileReader

  • ObjectInputStream

  • Formatter

Explicación

Pregunta 72 de 105

1

Consider the code segment below.

if ( gender == 1 )
{
if ( age >= 65 )
++seniorFemales;
} // end if

This segment is equivalent to which of the following?

Selecciona una de las siguientes respuestas posibles:

  • if ( gender == 1 || age >= 65 )

    ++seniorFemales;

  • if ( gender == 1 && age >= 65 )
    ++seniorFemales;

  • if ( gender == 1 AND age >= 65 )

    ++seniorFemales;

  • if ( gender == 1 OR age >= 65 )

    ++seniorFemales;

Explicación

Pregunta 73 de 105

1

A final field should also be declared ________ if it is initialized in its declaration.

Selecciona una de las siguientes respuestas posibles:

  • private.

  • public.

  • protected.

  • static.

Explicación

Pregunta 74 de 105

1

The ________ method displays an input dialog for reading a string. (Choose all that apply.)

Selecciona una o más de las siguientes respuestas posibles:

  • String string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);

  • String string = JOptionPane.showInputDialog(null, "Enter a string");

  • String string = JOptionPane.showInputDialog("Enter a string");

  • String string = JOptionPane.showInputDialog("Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);

  • String string = JOptionPane.showMessageDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);

Explicación

Pregunta 75 de 105

1

A default constructor has how many parameters?

Selecciona una de las siguientes respuestas posibles:

  • 0.

  • 1.

  • 2.

  • Variable.

Explicación

Pregunta 76 de 105

1

The ________ method immediately terminates the program.

Selecciona una de las siguientes respuestas posibles:

  • System.stop(0);

  • System.halt(0);

  • System.terminate(0);

  • System.exit(0);

  • System.quit(0);

Explicación

Pregunta 77 de 105

1

Sentinel-controlled repetition is also known as:

Selecciona una de las siguientes respuestas posibles:

  • Definite repetition.

  • Indefinite repetition.

  • Multiple repetition.

  • Double repetition.

Explicación

Pregunta 78 de 105

1

Polymorphism means ________.

Selecciona una de las siguientes respuestas posibles:

  • that a class can extend another class

  • that data fields should be declared private

  • that a class can contain another class

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

Explicación

Pregunta 79 de 105

1

Which of the following is not a syntax error?

Selecciona una de las siguientes respuestas posibles:

  • System.out.println( 'Hello world!' ):

  • System.out.println( "Hello . world!" );

  • System.out.println( "Hello world!" );

  • System.out.println( Hello world! );

Explicación

Pregunta 80 de 105

1

What is k after the following block executes?

{
int k = 2;
nPrint("A message", k);
}
System.out.println(k);

Selecciona una de las siguientes respuestas posibles:

  • 2

  • 1

  • 0

  • k is not defined outside the block. So, the program has a compile error

Explicación

Pregunta 81 de 105

1

The _________ of a class are also called the public services or the public interface that the class provides to its clients.

Selecciona una de las siguientes respuestas posibles:

  • public constructors.

  • public instance variables.

  • public methods.

  • All of the above.

Explicación

Pregunta 82 de 105

1

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

public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new Object();
System.out.println(a1);
System.out.println(a2);
}
}

class A {
int x;
public String toString() {
return "A's x is " + x;
}
}

Selecciona una o más de las siguientes respuestas posibles:

  • When executing System.out.println(a1), the toString() method in the Object class is invoked.

  • When executing System.out.println(a1), the toString() method in the A class is invoked.

  • When executing System.out.println(a2), the toString() method in the Object class is invoked.

  • The program cannot be compiled, because System.out.println(a1) is wrong and it should be replaced by System.out.println(a1.toString());

Explicación

Pregunta 83 de 105

1

What do the following statements do?

double[] array;

array = new double[ 14 ];

Selecciona una de las siguientes respuestas posibles:

  • Create a double array containing 13 elements.

  • Create a double array containing 14 elements.

  • Create a double array containing 15 elements.

  • Declare but do not create a double array.

Explicación

Pregunta 84 de 105

1

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as ________.

Selecciona una de las siguientes respuestas posibles:

  • pass by name

  • pass by value

  • pass by reference

  • method invocation

Explicación

Pregunta 85 de 105

1

Which of following is not a correct method in Character? (Choose all that apply.)

Selecciona una o más de las siguientes respuestas posibles:

  • isDigit()

  • toLowerCase(char)

  • isLetter(char)

  • toUpperCase()

  • isLetterOrDigit(char)

Explicación

Pregunta 86 de 105

1

Given the following classes and their objects:

class C1 {};
class C2 extends C1 {};
class C3 extends C1 {};

C2 c2 = new C2();
C3 c3 = new C3();

Analyze the following statement:

c2 = (C2)((C1)c3);

Selecciona una de las siguientes respuestas posibles:

  • You will get a runtime error because you cannot cast objects from sibling classes.

  • You will get a runtime error because the Java runtime system cannot perform multiple casting in nested form.

  • c3 is cast into c2 successfully.

  • The statement is correct.

Explicación

Pregunta 87 de 105

1

Every class in Java, except ________, extends an existing class.

Selecciona una de las siguientes respuestas posibles:

  • Integer.

  • Object.

  • String.

  • Class.

Explicación

Pregunta 88 de 105

1

By default, the classpath consists only of the ________. However, the classpath can be modified by providing the ________ option to the javac compiler.

Selecciona una de las siguientes respuestas posibles:

  • root directory of the package, -d.

  • current directory, -d.

  • root directory of the package, -classpath.

  • current directory, -classpath.

Explicación

Pregunta 89 de 105

1

Which of the following is not a compilation error?

Selecciona una de las siguientes respuestas posibles:

  • Neglecting to initialize a local variable in a method before it is used.

  • Placing a semicolon at the end of the first line of an if statement.

  • Omitting the left and right parenthesis for the condition of an if statement.

  • All are compilation errors.

Explicación

Pregunta 90 de 105

1

________ is a simple but incomplete version of a method.

Selecciona una de las siguientes respuestas posibles:

  • A non-main method

  • A method developed using top-down approach

  • A stub

  • A main method

Explicación

Pregunta 91 de 105

1

What is displayed by the following code?

public static void main(String[ ] args) throws Exception {
String[ ] tokens = "Welcome to Java".split("o");
for (int i = 0; i < tokens.length; i++) {
System.out.print(tokens[i] + " ");
}
}

Selecciona una de las siguientes respuestas posibles:

  • Welcome t Java

  • Welc me t Java

  • Welc me to Java

  • Welcome to Java

Explicación

Pregunta 92 de 105

1

Which of the following code segments does not increment val by 3:

Selecciona una de las siguientes respuestas posibles:

  • val += 3;

  • val = val+1;

    val = val+1;
    val = val+1;

  • c = 3;

    val = val + (c == 3 ? 2 : 3);

  • All of the above increment val by 3.

Explicación

Pregunta 93 de 105

1

The import declaration import *; ________.

Selecciona una de las siguientes respuestas posibles:

  • causes a compilation error.

  • imports all classes in the library.

  • imports the default classes in the library.

  • imports the classes in package java.lang.

Explicación

Pregunta 94 de 105

1

An instance of ________ describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully.

Selecciona una de las siguientes respuestas posibles:

  • RuntimeException

  • Throwable

  • Error

  • Exception

  • NumberFormatException

Explicación

Pregunta 95 de 105

1

An instance of ________ describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program.

Selecciona una de las siguientes respuestas posibles:

  • NumberFormatException

  • Error

  • RuntimeException

  • Throwable

  • Exception

Explicación

Pregunta 96 de 105

1

What is the value of result after the following Java statements execute?

int a, b, c, d, result;

a = 4;

b = 12;

c = 37;

d = 51;

result = d % a * c + a % b + a;

Selecciona una de las siguientes respuestas posibles:

  • 119

  • 51

  • 127

  • 59

Explicación

Pregunta 97 de 105

1

When method printf requires multiple arguments, the arguments are separated with ________.

Selecciona una de las siguientes respuestas posibles:

  • colons (:).

  • semicolons (;).

  • commas (,).

  • periods (.).

Explicación

Pregunta 98 de 105

1

Analyze the following statement:

double sum = 0;

for (double d = 0; d<10;) {
d += 0.1;
sum += sum + d;
}

Selecciona una de las siguientes respuestas posibles:

  • The program compiles and runs fine.

  • The program runs in an infinite loop because d<10 would always be true.

  • The program has a compile error because the control variable in the for loop cannot be of the double type.

  • The program has a compile error because the adjustment is missing in the for loop.

Explicación

Pregunta 99 de 105

1

Suppose x is 1. What is x after x -= 1?

Selecciona una de las siguientes respuestas posibles:

  • 0

  • 1

  • 2

  • -1

  • -2

Explicación

Pregunta 100 de 105

1

Stacks are known as ________ data structures.

Selecciona una de las siguientes respuestas posibles:

  • FIFO.

  • FILO.

  • LIFO.

  • LILO.

Explicación

Pregunta 101 de 105

1

Which statement is true when a superclass has protected instance variables?

Selecciona una de las siguientes respuestas posibles:

  • A subclass object can assign an invalid value to the superclass’s instance variables, thus leaving an object in an inconsistent state.

  • Subclass methods are more likely to be written so that they depend on the superclass’s data implementation.

  • We may need to modify all the subclasses of the superclass if the superclass implementation changes.

  • All of the above.

Explicación

Pregunta 102 de 105

1

If you enter 1 2 3, when you run this program, what will be the output?

import java.util.Scanner;

public class Test1 {
public static void main(String[ ] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
// Compute average
double average = (number1 + number2 + number3) / 3;
// Display result
System.out.println(average);
}
}

Selecciona una de las siguientes respuestas posibles:

  • 1.0

  • 2.0

  • 4.0

  • 3.0

Explicación

Pregunta 103 de 105

1

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing, Chicago, Singapore]?

Selecciona una de las siguientes respuestas posibles:

  • x.add(2, "Chicago")

  • x.add(1, "Chicago")

  • x.add("Chicago")

  • x.add(0, "Chicago")

Explicación

Pregunta 104 de 105

1

Which of the following statements are true?

Selecciona una de las siguientes respuestas posibles:

  • If a file (e.g., c:\temp.txt) does not exist, new File("c:\\temp.txt") creates a new file named c:\temp.txt.

  • If a directory (e.g., c:\liang) does not exist, new File("c:\liang") creates a new directory named c:\liang.

  • If a directory (e.g., c:\liang) does not exist, new File("c:\liang") returns null.

  • If a file (e.g., c:\temp.txt) does not exist, new File("c:\\temp.txt") returns null.

  • None of the above.

Explicación

Pregunta 105 de 105

1

The visibility of these modifiers increases in this order:

Selecciona una de las siguientes respuestas posibles:

  • none (if no modifier is used), private, protected, and public.

  • none (if no modifier is used), protected, private, and public.

  • private, protected, none (if no modifier is used), and public.

  • private, none (if no modifier is used), protected, and public.

Explicación