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

Nietrywialne pytania napotkane podczas nauki do OCAJP7. Może służyć do przypominania sobie mechanizmów języka.

106
0
0
 .  .
Creado por . . hace alrededor de 8 años
Cerrar

OCAJP7

Pregunta 1 de 48

1

Which of the following is illegal:

Selecciona una de las siguientes respuestas posibles:

  • int i = 32;

  • float f = 45.0;

  • double d = 45.0;

Explicación

Pregunta 2 de 48

1

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

Selecciona una de las siguientes respuestas posibles:

  • Compiles and runs with no output

  • Compiles and runs printing out The age is 1

  • Compiles but generates a runtime error

  • Does not compile

  • Compiles but generates a compile time error

Explicación

Pregunta 3 de 48

1

public static void main(String[] args) {
int age;
System.out.println(age+1);
}

Selecciona una de las siguientes respuestas posibles:

  • Compiles and runs with no output

  • Compiles and runs printing out The age is 1

  • Compiles but generates a runtime error

  • Does not compile

  • Compiles but generates a compile time error

Explicación

Pregunta 4 de 48

1

Which of the following return true?

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

  • "john" == "john"

  • "john".equals("john")

  • "john" = "john"

  • "john".equals(new Button("john"))

Explicación

Pregunta 5 de 48

1

Which of the following is correct:

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

  • String temp [] = new String {"j", "a", "z"};

  • String temp [] = {"a", "b", "c"};

  • String temp = {"a", "b", "c"};

  • String temp [] = new String [] {"j" "a" "z"};

  • String temp [] = new String[3] {"j" "a" "z"};

Explicación

Pregunta 6 de 48

1

Compiler adds default constructor to class which hasn't got constructor with empty argument list. Is it true?

Selecciona uno de los siguientes:

  • VERDADERO
  • FALSO

Explicación

Pregunta 7 de 48

1

Which of the following are acceptable to the Java 7 compiler?

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

  • if (2 == 3) System.out.println("Ok");

  • if (false) System.out.println("Ok");

  • if (true) System.out.println("Ok");

  • boolean b = false; if (b = true) System.out.println("Ok");

Explicación

Pregunta 8 de 48

1

Assuming a method contains code which may raise an Exception (but not a Runtime Exception), what is the correct way for a method to indicate that it expects the caller to handle that exception:

Selecciona una de las siguientes respuestas posibles:

  • throw Exception

  • throws Exception

  • Don't need to specify anything

Explicación

Pregunta 9 de 48

1

Czy w jednym konstruktorze można wywołać inny konstruktor z tej samej klasy i konstruktor z klasy bazowej jednocześnie?

Selecciona uno de los siguientes:

  • VERDADERO
  • FALSO

Explicación

Pregunta 10 de 48

1

Which variables can an inner class access from the class which encapsulates it?

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

  • All static variables

  • All final variables

  • All instance variables

  • Only final instance variables

  • Only final static variables

Explicación

Pregunta 11 de 48

1

In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
1. public class Test {
2. public static void main (String args []) {
3. Employee e = new Employee("Bob", 48);
4. e.calculatePay();
5. System.out.println(e.printDetails());
6. e = null;
7. e = new Employee("Denise", 36);
8. e.calculatePay();
9. System.out.println(e.printDetails());
10. }
11. }

Selecciona una de las siguientes respuestas posibles:

  • Line 7

  • Line 8

  • Line 10

  • Line 11

  • Never

  • At the end of function

Explicación

Pregunta 12 de 48

1

Given the following code what is the effect of a being 5:

public class Test {
public void add(int a) {
loop: for (int i = 1; i < 3; i++){
for (int j = 1; j < 3; j++) {
if (a == 5) {
break loop;
}
System.out.println(i * j);
}
}
}
}

Selecciona una de las siguientes respuestas posibles:

  • Generate a runtime error

  • Throw an ArrayIndexOutOfBoundsException

  • Print the values: 1, 2, 2, 4

  • Produces no output

Explicación

Pregunta 13 de 48

1

What is the result of executing the following fragment of code:

boolean flag = false;
if (flag = true) {
System.out.println("true");
} else {
System.out.println("false");
}
}

Selecciona una de las siguientes respuestas posibles:

  • true is printed to standard out

  • false is printed to standard out

  • An exception is raised

  • Nothing happens

Explicación

Pregunta 14 de 48

1

What will be the output of the program?

public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}

Selecciona una de las siguientes respuestas posibles:

  • Finally

  • Compilation fails

  • The code runs with no output.

  • An exception is thrown at runtime.

Explicación

Pregunta 15 de 48

1

Which of the following are correct. Select the one correct answer.

Selecciona una de las siguientes respuestas posibles:

  • An import statement, if defined, must always be the first non-comment statement of the file.

  • private members are accessible to all classes in the same package.

  • An abstract class can be declared as final.

  • Local variables cannot be declared as static.

Explicación

Pregunta 16 de 48

1

Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.

Selecciona una de las siguientes respuestas posibles:

  • valueOf

  • intValue

  • getInt

  • getInteger

Explicación

Pregunta 17 de 48

1

Which code determines the int value data closer to, but not greater than, a double value b?

Selecciona una de las siguientes respuestas posibles:

  • Int data = (int) Math.floor(b);

  • Int data = (int) Math.abs(b);

  • Int data = (int) Math.ceil(b);

  • Int data = (int) Math.min(b);

Explicación

Pregunta 18 de 48

1

Which statement is true for the Class java.util.HashSet?

Selecciona una de las siguientes respuestas posibles:

  • The elements in the collection are unique.

  • The collection is guaranteed to be immutable

  • The elements in the collection are ordered.

  • The elements in the collection are synchronized.

Explicación

Pregunta 19 de 48

1

What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}

Selecciona una de las siguientes respuestas posibles:

  • BC is printed before exiting with an error

  • Compilation fails.

  • ABCD

  • C is printed before exiting with an error message.

Explicación

Pregunta 20 de 48

1

What is valid returnType for getData?
public Class returnData
{
<returnType> getData(byte a, double z)
{
return (short)a/z * 10;
}
}

Selecciona una de las siguientes respuestas posibles:

  • Short

  • Byte

  • Int

  • Double

Explicación

Pregunta 21 de 48

1

What is the result?
int index = 1;
Boolean [] test = new Boolean[3];
Boolean data = test[index];

Selecciona una de las siguientes respuestas posibles:

  • data has the value of true

  • The code will not compile.

  • data has the value of false

  • data has the value of null

Explicación

Pregunta 22 de 48

1

What will be the output of the program?

class A
{
final public int GetResult(int a, int b) { return 0; }
}
class B extends A
{
public int GetResult(int a, int b) {return 1; }
}
public class Test
{
public static void main(String args[])
{
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}

Selecciona una de las siguientes respuestas posibles:

  • x = 0

  • x = 1

  • Compilation fails.

  • An exception is thrown at runtime.

Explicación

Pregunta 23 de 48

1

class SC2
{
public static void main(String [] args)
{
SC2 s = new SC2();
s.start();
}

void start()
{
int a = 3;
int b = 4;
System.out.print(" " + 7 + 2 + " ");
System.out.print(a + b);
System.out.print(" " + a + b + " ");
System.out.print(foo() + a + b + " ");
System.out.println(a + b + foo());
}

String foo()
{
return "foo";
}
}

Selecciona una de las siguientes respuestas posibles:

  • 9 7 7 foo 7 7foo

  • 72 34 34 foo34 34foo

  • 9 7 7 foo34 34foo

  • 72 7 34 foo34 7foo

Explicación

Pregunta 24 de 48

1

Float f = new Float("12");
switch (f)
{
case 12: System.out.println("Twelve");
case 0: System.out.println("Zero");
default: System.out.println("Default");
}

Selecciona una de las siguientes respuestas posibles:

  • Zero

  • Twelve

  • Default

  • Compilation fails

Explicación

Pregunta 25 de 48

1

Which statement is true for the class java.util.ArrayList?

Selecciona una de las siguientes respuestas posibles:

  • The elements in the collection are ordered.

  • The collection is guaranteed to be immutable.

  • The elements in the collection are guaranteed to be unique.

  • The elements in the collection are accessed using a unique key.

Explicación

Pregunta 26 de 48

1

public class Test
{
public void foo()
{
assert false; /* Line 5 */
assert false; /* Line 6 */
}
public void bar()
{
while(true)
{
assert false; /* Line 12 */
}
assert false; /* Line 14 */
}
}

Selecciona una de las siguientes respuestas posibles:

  • Line 5

  • Line 6

  • Line 12

  • Line 14

Explicación

Pregunta 27 de 48

1

What will be the output of the program?

public class Test138
{
public static void stringReplace (String text)
{
text = text.replace ('j' , 'c'); /* Line 5 */
}
public static void bufferReplace (StringBuffer text)
{
text = text.append ("c"); /* Line 9 */
}
public static void main (String args[])
{
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer);
}
}

Selecciona una de las siguientes respuestas posibles:

  • java

  • javac

  • cavajavac

  • javajavac

  • Compile error

Explicación

Pregunta 28 de 48

1

Which declaration of the main method below would allow a class to be started as a standalone program.

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

  • public static int main(char args[])

  • public static void main(String args[])

  • public static void main(String args)

  • public static void main(String... args)

Explicación

Pregunta 29 de 48

1

Which of these are legal array declarations or definitions?

Selecciona una de las siguientes respuestas posibles:

  • int[] []x[];

  • int x[5];

  • int *x;

  • None of above

Explicación

Pregunta 30 de 48

1

Which of the following are keywords in Java.

Selecciona una de las siguientes respuestas posibles:

  • implement

  • friend

  • NULL

  • synchronized

Explicación

Pregunta 31 de 48

1

Which of these are legal identifiers.

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

  • number_1

  • number_a

  • $1234

  • -volatile

Explicación

Pregunta 32 de 48

1

The class Hashtable is used to implement which collection interface.

Selecciona una de las siguientes respuestas posibles:

  • List

  • Set

  • Map

  • SortedSet

Explicación

Pregunta 33 de 48

1

TreeMap class is used to implement which collection interface. Select the one correct answer.

Selecciona una de las siguientes respuestas posibles:

  • Set

  • SortedSet

  • Tree

  • SortedMap

Explicación

Pregunta 34 de 48

1

What gets displayed on the screen when the following program is compiled and run.

protected class example {
public static void main(String args[]) {
String test = "abc";
test = test + test;
System.out.println(test);
}
}

Selecciona una de las siguientes respuestas posibles:

  • The class does not compile because the top level class cannot be protected.

  • The program prints "abc"

  • The program prints "abcabc"

  • The program does not compile because statement "test = test + test" is illegal.

Explicación

Pregunta 35 de 48

1

class xyz {
static int i;
public static void main(String args[]) {
while (i < 0) {
i--;
}
System.out.println(i);
}
}

Selecciona una de las siguientes respuestas posibles:

  • The program does not compile as i is not initialized.

  • The program prints -1.

  • The program compiles but does not run.

  • The program compiles and runs but does not print anything.

  • The program prints 0.

Explicación

Pregunta 36 de 48

1

What gets printed on the standard output when the class below is compiled and executed.
class A {
boolean b = true, f;
private void testujemy() {
int i = 0;
boolean t = true;
b = (t || ((i++) == 0));
b = (f || ((i+=2) > 0));
System.out.println(i);
}
}

Selecciona una de las siguientes respuestas posibles:

  • 0

  • 1

  • 2

  • 3

  • 4

  • Compilation error

  • Runtime exception.

Explicación

Pregunta 37 de 48

1

A class can have many methods with the same name as long as the number of parameters or type of parameters is different. This OOP concept is known as

Selecciona una de las siguientes respuestas posibles:

  • Method Invocating

  • Method Overriding

  • Method Labeling

  • Method Overloading

Explicación

Pregunta 38 de 48

1

Using up to four characters what is the Java representation of the number 23 in hex?

Selecciona una de las siguientes respuestas posibles:

  • 0x17

  • 0x18

  • 0x19

  • 0x20

Explicación

Pregunta 39 de 48

1

What are the two parts of a value of type double?

Selecciona una de las siguientes respuestas posibles:

  • Length, Denominator

  • Significant Digits, Exponent

  • Mode, Numerator

  • Length, Numerator

Explicación

Pregunta 40 de 48

1

Using up to four characters, write the Java representation of integer literal 3 in hexadecimal.

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

  • 0x03

  • 0x3

  • 0X3

  • 0f3

  • 3

Explicación

Pregunta 41 de 48

1

What gets printed when the following program is compiled and run. Select the one correct answer.

public class test {
public static void main(String args[]) {
byte x = 3;
x = (byte)~x;
System.out.println(x);
}
}

Selecciona una de las siguientes respuestas posibles:

  • 0

  • 3

  • -4

  • none of these

Explicación

Pregunta 42 de 48

1

Java endianness is:

Selecciona una de las siguientes respuestas posibles:

  • Java is big endian

  • Java is little endian

Explicación

Pregunta 43 de 48

1

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.

public class test {
public static void main(String args[]) {
int x,y;
x = 3 & 5;
y = 3 | 5;
System.out.println(x + " " + y);
}
}

Selecciona una de las siguientes respuestas posibles:

  • 7 1

  • 3 7

  • 1 7

  • 1 3

Explicación

Pregunta 44 de 48

1

What will be the output of code:

switch(3) {
case 3: continue;
case 4: System.out.println("Case 3 and 4");
break;
case 5: System.out.println("Case 5");
}

Selecciona una de las siguientes respuestas posibles:

  • Case 3 and 4

  • Case 3 and 4
    Case 5

  • Runtime exception

  • Compilation error

Explicación

Pregunta 45 de 48

1

In switch statement the default case must be at the end of switch body.

Selecciona uno de los siguientes:

  • VERDADERO
  • FALSO

Explicación

Pregunta 46 de 48

1

Given two non-negative integers a and b and a String str, what is the number of characters in the expression str.substring(a,b) . Select the one correct answer.

Selecciona una de las siguientes respuestas posibles:

  • a - b

  • b - a

  • b - a - 1

  • a - b - 1

  • b - a + 1

Explicación

Pregunta 47 de 48

1

All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character) in java are

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

  • final

  • private

  • immutable

  • Serializable

Explicación

Pregunta 48 de 48

1

Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is executed?
String str = new String("Java");
char fourthChar = str.charAt(4);

Selecciona una de las siguientes respuestas posibles:

  • 'a'

  • throws StringIndexOutofBoundsException

  • null characater

Explicación