image Strona Główna       image SKFAB00GBB       image ceelt smp       image Artykul1       image ArmyBeasts       image 2006 nov p3       

Odnośniki

[ Pobierz całość w formacie PDF ]

9.
10. void start() {
11. int x = 7;
12. twice(x);
13. System.out.print(x + " ");
14. }
15.
16. void twice(int x) {
17. x = x*2;
18. s = x;
19. }
20. }
what is the result?
A. 77
B. 714
C. 140
D. 1414
E. Compilation fails
F. An exception is thrown at runtime
14. Given the following,
1. class Test {
2. public static void main(String [] args) {
3. Test p = new Test();
4. p.start();
5. }
6.
7. void start() {
8. boolean b1 = false;
9. boolean b2 = fix(b1);
10. System.out.println(b1 + " " + b2);
11. }
12.
13. boolean fix(boolean b1) {
14. b1 = true;
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
Composite Default screen
Chapter 3: Operators and Assignments
58
15. return b1;
16. }
17. }
what is the result?
A. truetrue
B. falsetrue
C. truefalse
D. falsefalse
E. Compilation fails
F. An exception is thrown at runtime
15. Given the following,
1. class PassS {
2. public static void main(String [] args) {
3. PassS p = new PassS();
4. p.start();
5. }
6.
7. void start() {
8. String s1 = "slip";
9. String s2 = fix(s1);
10. System.out.println(s1 + " " + s2);
11. }
12.
13. String fix(String s1) {
14. s1 = s1 + "stream";
15. System.out.print(s1 + " ");
16. return "stream";
17. }
18. }
what is the result?
A. slipstream
B. slipstreamstream
C. streamslipstream
D. slipstreamslipstream
E. Compilation fails
F. An exception is thrown at runtime
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
Composite Default screen
Self Test
59
16. Given the following,
1. class SC2 {
2. public static void main(String [] args) {
3. SC2 s = new SC2();
4. s.start();
5. }
6.
7. void start() {
8. int a = 3;
9. int b = 4;
10. System.out.print(" " + 7 + 2 + " ");
11. System.out.print(a + b);
12. System.out.print(" " + a + b + " ");
13. System.out.print(foo() + a + b + " ");
14. System.out.println(a + b + foo());
15. }
16.
17. String foo() {
18. return "foo";
19. }
20. }
what is the result?
A. 977foo77foo
B. 723434foo3434foo
C. 977foo3434foo
D. 72734foo347foo
E. 93434foo3434foo
17. Given the following,
1. class PassA {
2. public static void main(String [] args) {
3. PassA p = new PassA();
4. p.start();
5. }
6.
7. void start() {
8. long [] a1 = {3,4,5};
9. long [] a2 = fix(a1);
10. System.out.print(a1[0] + a1[1] + a1[2] + " ");
11. System.out.println(a2[0] + a2[1] + a2[2]);
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
Composite Default screen
Chapter 3: Operators and Assignments
60
12. }
13.
14. long [] fix(long [] a3) {
15. a3[1] = 7;
16. return a3;
17. }
18. }
what is the result?
A. 1215
B. 1515
C. 345375
D. 375375
E. Compilation fails
F. An exception is thrown at runtime
18. Given the following,
1. class Two {
2. byte x;
3. }
4.
5. class PassO {
6. public static void main(String [] args) {
7. PassO p = new PassO();
8. p.start();
9. }
10.
11. void start() {
12. Two t = new Two();
13. System.out.print(t.x + " ");
14. Two t2 = fix(t);
15. System.out.println(t.x + " " + t2.x);
16. }
17.
18. Two fix(Two tt) {
19. tt.x = 42;
20. return tt;
21. }
22. }
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
Composite Default screen
Self Test
61
what is the result?
A. nullnull42
B. 0042
C. 04242
D. 000
E. Compilation fails
F. An exception is thrown at runtime
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
Composite Default screen
Chapter 3: Operators and Assignments
62
SELF TEST ANSWERS
Java Operators (Sun Objective 5.1)
1. B and D. B and D both evaluate to 32. B is shifting bits right then left using the signed
bit shifters >> and >, but since the
beginning number is positive the sign is maintained.
A evaluates to 8, C looks like 2 to the 5th power, but ^ is the Exclusive OR operator so C
evaluates to 7. E evaluates to 16, and F evaluates to 0 (2 >> 5 is not 2 to the 5th).
2. B and D. B is correct because class type Ticker is part of the class hierarchy of t; therefore
it is a legal use of the instanceof operator. D is also correct because Component is part of the
hierarchy of t, because Ticker extends Component in line 2.
A is incorrect because the syntax is wrong. A variable (ornull) always appears before the
instanceof operator, and a type appears after it. C and E are incorrect because the statement is
used as a method, which is illegal. F is incorrect because the String class is not in the hierarchy
of the t object.
3. C. The code will not compile because in line 5, the line will work only if we use (x==y)
in the line. The == operator compares values to produce aboolean, whereas the = operator
assigns a value to variables.
A, B, and D are incorrect because the code does not get as far as compiling. If we corrected
this code, the output would be false.
4. B, D, and E. B is correct because the reference variables f1 and f3 refer to the same array
object. D is correct because it is legal to compare integer and floating-point types. E is correct
because it is legal to compare a variable with an array element.
C is incorrect because f2 is an array object and f1[1] is an array element.
5. A. The >>> operator moves all bits to the right, zero filling the left bits. The bit
transformation looks like this:
Before:10000000000000000000000000000000
After:00000000000000000000000000000001
C is incorrect because the >>> operator zero fills the left bits, which in this case changes
the sign of x, as shown. B is incorrect because the output methodprint()always displays
integers in base 10. D is incorrect because this is the reverse order of the two output numbers.
E is incorrect because there was a correct answer.
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 3
Composite Default screen
Self Test Answers
63
6. D. The & operator produces a 1 bit when both bits are 1. The result of the & operation
is 9. The ^ operator produces a 1 bit when exactly one bit is 1; the result of this operation is 10.
The | operator produces a 1 bit when at least one bit is 1; the result of this operation is 14.
A, B, C, and E, are incorrect based on the program logic described above.
7. A, B, C, and D. A is correct because when a floating-point number (a double in this case)
is cast to an int, it simply loses the digits after the decimal. B and D are correct because a long
can be cast into a byte. If the long is over 127, it loses its most significant (leftmost) bits. C
actually works, even though a cast is not necessary, because a long can store a byte.
There are no incorrect answer choices.
Logical Operators (Sun Objective 5.3)
8. B. The first two iterations of the for loop both x and y are incremented. On the third
iteration x is incremented, and for the first time becomes greater than 2. The short circuitor
operator || keeps y from ever being incremented again and x is incremented twice on each of [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • blacksoulman.xlx.pl