.  .
Quiz von , erstellt am more than 1 year ago

Z książki.

123
0
0
 .  .
Erstellt von . . vor etwa 8 Jahre
Schließen

OCAJP7 part 3 - from book

Frage 1 von 20

1

Only public and protected constructors are inherited from super class if the subclass is not in the same package.

Wähle eins der folgenden:

  • WAHR
  • FALSCH

Erklärung

Frage 2 von 20

1

Which constructor is valid in class BlaBla

Wähle eine oder mehr der folgenden:

  • BlaBla(BlaBla a)

  • private BlaBla()

  • public final BlaBla(int i)

  • public static BlaBla(char o)

Erklärung

Frage 3 von 20

1

Given the following code, which of these constructors can be added to class B without
causing a compile time error?
class A{
int i;
public A(int x) { this.i = x; }
}
class B extends A{
int j;
public B(int x, int y) {
super(x);
this.j = y;
}
}

Wähle eine oder mehr der folgenden:

  • B( ) { }

  • B(int y ) { j = y; }

  • B(int y ) { super(y*2 ); j = y; }

  • B(int y ) { i = y; j = y*2; }

  • B(int z ) { this(z, z); }

Erklärung

Frage 4 von 20

1

Consider the following array definitions:
int[] array1, array2[];
int[][] array3;
int[] array4[], array5[];
Which of the following are valid statements?

Wähle eine oder mehr der folgenden:

  • array2 = array3;

  • array2 = array4;

  • array1 = array2;

  • array4 = array1;

  • array5 = array3

Erklärung

Frage 5 von 20

1

What will be the result of trying to compile and execute of the following program?
public class TestClass{
public static void main(String args[] ){
int i = 0 ;
int[] iA = {10, 20} ;
iA[i] = i = 30 ;
System.out.println(""+ iA[ 0 ] + " " + iA[ 1 ] + " "+i) ;
}
}

Wähle eine der folgenden:

  • It will throw ArrayIndexOutofBoundsException at Runtime.

  • Compile time Error.

  • It will prints 10 20 30

  • It will prints 30 20 30

  • It will prints 0 20 30

Erklärung

Frage 6 von 20

1

What will the following program print?
class Test{
public static void main(String[] args){
int i = 4;
int ia[][][] = new int[i][i = 3][i];
System.out.println( ia.length + ", " + ia[0].length+", "+ ia[0][0].length);
}
}

Wähle eine der folgenden:

  • It will not compile.

  • 3, 4, 3

  • 3, 3, 3

  • 4, 3, 4

  • 4, 3, 3

Erklärung

Frage 7 von 20

1

Consider the following program...
class ArrayTest{
public static void main(String[] args){
int ia[][] = { {1, 2}, null };
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
System.out.println(ia[i][j]);
}
}
Which of the following statements are true?

Wähle eine der folgenden:

  • It will not compile.

  • It will throw an ArrayIndexOutOfBoundsException at Runtime.

  • It will throw a NullPointerException at Runtime.

  • It will compile and run without throwing any exceptions.

  • None of the above.

Erklärung

Frage 8 von 20

1

Consider the following class...
class Test{
public static void main(String[ ] args){
int[] a = { 1, 2, 3, 4 };
int[] b = { 2, 3, 1, 0 };
System.out.println( a [ (a = b)[3] ] );
}
}
What will it print when compiled and run ?

Wähle eine der folgenden:

  • It will not compile.

  • It will throw ArrayIndexOutOfBoundsException when run.

  • It will print 1.

  • It will print 3.

  • It will print 4

  • It will print 0

Erklärung

Frage 9 von 20

1

Given the following program, which statements are true?
// Filename: TestClass.java
public class TestClass{
public static void main(String args[]){
A[] a, a1;
B[] b;
a = new A[10]; a1 = a;
b = new B[20];
a = b; // 1
b = (B[]) a; // 2
b = (B[]) a1; // 3
}
}
class A { }
class B extends A { }

Wähle eine der folgenden:

  • Compile time error at line 3.

  • The program will throw a java.lang.ClassCastException at the line labelled 2 when run.

  • The program will throw a java.lang.ClassCastException at the line labelled 3 when run.

  • The program will compile and run if the (B[ ] ) cast in the line 2 and the whole line 3 is removed.

Erklärung

Frage 10 von 20

1

Which of these statements are true?

Wähle eine oder mehr der folgenden:

  • If a RuntimeException is not caught, the method will terminate and normal
    execution of the thread will resume.

  • An overriding method must declare that it throws the same exception classes as the
    method it overrides.

  • The main method of a program can declare that it throws checked exceptions.

  • A method declaring that it throws a certain exception class may throw instances of
    any subclass of that exception class.

  • finally blocks are executed if and only if an exception gets thrown while inside the
    corresponding try block.

Erklärung

Frage 11 von 20

1

Consider the following code...
public class TestClass{
class MyException extends Exception {}
public void myMethod() throws XXXX{
throw new MyException();
}
}

Can we replace XXXX with MyException?

Wähle eins der folgenden:

  • WAHR
  • FALSCH

Erklärung

Frage 12 von 20

1

What will the following program print?
class Test{
public static void main(String[] args){
int i = 4;
int ia[][][] = new int[i][i = 3][i];
System.out.println( ia.length + ", " + ia[0].length+", "+ ia[0][0].length);
}
}

Wähle eine der folgenden:

  • It will not compile.

  • 3, 4, 3

  • 3, 3, 3

  • 4, 3, 4

  • 4, 3, 3

Erklärung

Frage 13 von 20

1

What will the following code print ?
class Test{
public static void main(String[] args){
int k = 1;
int[] a = { 1 };
k += (k = 4) * (k + 2);
a[0] += (a[0] = 4) * (a[0] + 2);
System.out.println( k + " , " + a[0]);
}
}

Wähle eine der folgenden:

  • It will not compile.

  • 4 , 4

  • 25 , 25

  • 13 , 13

  • None of the above.

Erklärung

Frage 14 von 20

1

What will the following code print when compiled and run?
class Base{
void methodA(){
System.out.println("base - MethodA");
}
}
class Sub extends Base{
public void methodA(){
System.out.println("sub - MethodA");
}
public void methodB(){
System.out.println("sub - MethodB");
}
public static void main(String args[]){
Base b=new Sub(); //1
b.methodA(); //2
b.methodB(); //3
}
}

Wähle eine der folgenden:

  • sub - MethodA and sub - MethodB

  • base - MethodA and sub - MethodB

  • Compile time error at //1

  • Compile time error at //2

  • Compile time error at //3

Erklärung

Frage 15 von 20

1

What will be printed?
class A1 {
static int i;
}
class A {
public static void main(String[] args) {
A1 a1 = null;
System.out.println(a1.i);
}
}

Wähle eine der folgenden:

  • 10

  • This code will not compile.

  • NullpointerException will be thrown

  • 0

Erklärung

Frage 16 von 20

1

What will be the output of:
Short k = 9; Integer i = 9; System.out.println(k == i);

Please provide argumentation to your answer.

Wähle eine der folgenden:

  • true

  • false

  • Compilation error

  • Exception in runtime

  • Other

Erklärung

Frage 17 von 20

1

Consider the following code:
class A{
public XXX m1(int a){
return a*10/4-30;
}
}
class A2 extends A{
public YYY m1(int a){
return a*10/4.0;
}
}
What can be substituted for XXX and YYY so that it can compile without any
problems?

Wähle eine der folgenden:

  • int, int

  • int, double

  • double, double

  • double, int

  • Nothing, they are simply not compatible.

Erklärung

Frage 18 von 20

1

Consider the following code:
class A{
A() { print();
}
void print() { System.out.println("A"); }
}
class B extends A{
int i =
Math.round(3.5f);
public static void main(String[] args){
A a = new B();
a.print();
}
void print() { System.out.println(i); }
}
What will be the output when class B is run ?

Wähle eine der folgenden:

  • It will print A, 4.

  • It will print A, A

  • It will print 0, 4

  • It will print 4, 4

  • None of the above.

Erklärung

Frage 19 von 20

1

Consider :
class A { public void perform_work(){} }
class B extends A { public void perform_work(){}
class C extends B { public void perform_work(){}
}
}
How can you let perform_work() method of A to be called from an instance method in C?

Wähle eine der folgenden:

  • ( (A) this ).perform_work( );

  • super.perform_work( );

  • super.super.perform_work( );

  • this.super.perform_work( );

  • It is not possible.

Erklärung

Frage 20 von 20

1

Expression (s instanceof java.util.Date) will return false if 's' was declared
as a variable of class java.lang.String .

Wähle eins der folgenden:

  • WAHR
  • FALSCH

Erklärung