Oracle sual nümunələri Sual nümunələri

1Z0-804 (OCP 7) imtahan sualı nümunələri (Oracle)

1z0-804 sample exam questions
Written by Mushfiq Mammadov

1. Given:

class MySort implements Comparator<Integer> {
[nbsp count=4]public int compare(Integer x, Integer y) {
[nbsp count=8]return y.compareTo(x);
[nbsp count=4]}
}

And the code fragment:

[nbsp count=4]Integer[] primes = {2, 7, 5, 3};
[nbsp count=4]MySort ms = new MySort();
[nbsp count=4]Arrays.sort(primes, ms);
[nbsp count=4]for (Integer p2 : primes) {
[nbsp count=8]System.out.print(p2 + " ");
[nbsp count=4]}

What is the result?

A) 2 3 5 7
B) 2 7 5 3
C) 7 5 3 2
D) Compilation fails.

 

2. Given:

class Class1 { String v1; }
class Class2 {
[nbsp count=4]Class1 c1;
[nbsp count=4]String v2;
}
class Class3 {
[nbsp count=4]Class2 c1;
[nbsp count=4]String v3;
}

Which three options correctly describe the relationship between the classes?

A) Class2 has-a v3
B) Class1 has-a v2
C) Class2 has-a v2
D) Class3 has-a v1
E) Class2 has-a Class3
F) Class2 has-a Class1

 

3. Given:

class MyKeys {
[nbsp count=4]Integer key;
[nbsp count=4]MyKeys(Integer k) {
[nbsp count=8]key = k;
[nbsp count=4]}
[nbsp count=4]public boolean equals(Object o) {
[nbsp count=8]return ((MyKeys) o).key == this.key;
[nbsp count=4]}
}

And this code snippet:

Map m = new HashMap();
MyKeys m1 = new MyKeys(1);
MyKeys m2 = new MyKeys(2);
MyKeys m3 = new MyKeys(1);
MyKeys m4 = new MyKeys(new Integer(2));
m.put(m1, "car");
m.put(m2, "boat");
m.put(m3, "plane");
m.put(m4, "bus");
System.out.print(m.size());

What is the result?

A) 2
B) 3
C) 4
D) Compilation fails.

 

4. Given:

import java.util.*;
public class MyScan {
[nbsp count=4]public static void main(String[] args) {
[nbsp count=8]String in = "1 a 10 . 100 1000";
[nbsp count=8]Scanner s = new Scanner(in);
[nbsp count=8]int accum = 0;
[nbsp count=8]for (int x = 0; x < 4; x++) {
[nbsp count=12]accum += s.nextInt();
[nbsp count=8]}
[nbsp count=8]System.out.println(accum);
[nbsp count=4]}
}

What is the result?

A) 11
B) 111
C) 1111
D) An exception is thrown at runtime.

 

5. Given:

public class Truthy {
[nbsp count=4]public static void main(String[] args) {
[nbsp count=8]int x = 7;
[nbsp count=8]assert (x == 6) ? "x == 6" : "x != 6";
[nbsp count=4]}
}

What is the result if you try to compile Truthy.java and then run it with assertions enabled?

A) Truthy.java does NOT compile.
B) Truthy.java compiles and the output is x != 6.
C) Truthy.java compiles and an AssertionError is thrown with no additional output.
D) Truthy.java compiles and an AssertionError is thrown with x != 6 as additional output.

 

6. Given the code fragment:

try {
// assume "conn" is a valid Connection object
// assume a valid Statement object is created
// assume rollback invocations will be valid

// use SQL to add 10 to a checking account
Savepoint s1 = conn.setSavePoint();
// use SQL to add 100 to the same checking account

Savepoint s2 = conn.setSavePoint();
// use SQL to add 1000 to the same checking account
// insert valid rollback method invocation here
} catch (Exception e) { }

Which two statements are true?

A) If conn.rollback(s1) is inserted, account will be incremented by 10.
B) If conn.rollback(s1) is inserted, account will be incremented by 1010.
C) If conn.rollback(s2) is inserted, account will be incremented by 100.
D) If conn.rollback(s2) is inserted, account will be incremented by 110.
E) If conn.rollback(s2) is inserted, account will be incremented by 1110.

 

7. Given:

public class Bees {
[nbsp count=4]public static void main(String[] args) {
[nbsp count=8]try {
[nbsp count=12]new Bees().go();
[nbsp count=8]} catch (Exception e) {
[nbsp count=12]System.out.println("thrown to main");
[nbsp count=8]}
[nbsp count=4]}
[nbsp count=4]synchronized void go() throws InterruptedException {
[nbsp count=8]Thread t1 = new Thread();
[nbsp count=8]t1.start();
[nbsp count=8]System.out.print("1 ");
[nbsp count=8]t1.wait(5000);
[nbsp count=8]System.out.print("2 ");
[nbsp count=4]}
}

What is the result?

A) The program prints 1 then 2 after 5 seconds
B) The program prints: 1 thrown to main
C) The program prints: 1 2 thrown to main
D) The program prints:1 then t1 waits for its notification.

 

8. Given:

import java.text.*;
public class Align {
[nbsp count=4]public static void main(String[] args) throws ParseException {
[nbsp count=8]String[] sa = {"111.234", "222.5678"};
[nbsp count=8]NumberFormat nf = NumberFormat.getInstance();
[nbsp count=8]nf.setMaximumFractionDigits(3);
[nbsp count=8]for (String s : sa) {
[nbsp count=12]System.out.println(nf.parse(s));
[nbsp count=8]}
[nbsp count=4]}
}

What is the result?

A)
111.234
222.567

B)
111.234
222.568

C)
111.234
222.5678

D) An exception is thrown at runtime.

 

Cavablar

1. C
2. C, D, F
3. C
4. D
5. A
6. A, D
7. B
8. C

 

Mənbə: Oracle, Exam 804: Java SE 7

About the author

Mushfiq Mammadov

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.