SCJP MATERIAL
  <<Back To SCJP Material Main Page
Page: 2

3. Operators

7. Given:
1. class Comp2 {
2. public static void main(String[] args) {
3. float f1 = 2.3f;
4. float[][] f2 = {{42.0f}, {1.7f, 2.3f}, {2.6f, 2.7f}};
5. float[] f3 = {2.7f};
6. Long x = 42L;
7. // insert code here
8. System.out.println("true");
9. }
10. }
And the following five code fragments:
F1. if(f1 == f2)
F2. if(f1 == f2[2][1])
F3. if(x == f2[0][0])
F4. if(f1 == f2[1,1])
F5. if(f3 == f2[2])
What is true?
A. One of them will compile, only one will be true.
B. Two of them will compile, only one will be true.
C. Two of them will compile, two will be true.
D. Three of them will compile, only one will be true.
E. Three of them will compile, exactly two will be true.
F. Three of them will compile, exactly three will be true.
Answer:
-> D is correct. Fragments F2, F3, and F5 will compile, and only F3 is true.
-> A, B, C, E, and F are incorrect. F1 is incorrect because you can’t compare a primitive   to an array. F4 is incorrect syntax to access an element of a two-dimensional array.

8. Given:
class Fork {
public static void main(String[] args) {
if(args.length == 1 | args[1].equals("test")) {
System.out.println("test case");
} else {
System.out.println("production " + args[0]);
} } }
And the command-line invocation:
java Fork live2
What is the result?
A. test case
B. production
C. test case live2
D. Compilation fails.
E. An exception is thrown at runtime.
Answer:
->  E is correct. Because the short circuit (||) is not used, both operands are evaluated. Since args[1] is past the args array bounds, an ArrayIndexOutOfBoundsException is thrown.
-> A, B, C, and D are incorrect based on the above.

9. Given:
class Foozit {
public static void main(String[] args) {
Integer x = 0;
Integer y = 0;
for(Short z = 0; z < 5; z++)
if((++x > 2) || (++y > 2))
x++;
System.out.println(x + " " + y);
} }
What is the result?
A. 5 1      B. 5 2      C. 5 3      D. 8 1
E. 8 2      F. 8 3      G. 10 2     H. 10 3
Answer:
->  E is correct. The first two times the if test runs, both x and y are incremented once (the x++ is not reached until the third iteration). Starting with the third iteration of the loop, y is never touched again, because of the short-circuit operator.
->  A, B, C, D, F, G, and H are incorrect based on the above.

10. Given:
class Titanic {
public static void main(String[] args) {
Boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
if((b1 & b2) | (b2 & b3) & b3)
System.out.print("alpha ");
if((b1 = false) | (b1 & b3) | (b1 | b2))
System.out.print("beta ");
} }
What is the result?
A. beta
B. alpha
C. alpha beta
D. Compilation fails.
E. No output is produced.
F. An exception is thrown at runtime.
Answer:
-> E is correct. In the second if test, the leftmost expression is an assignment, not
a comparison. Once b1 has been set to false, the remaining tests are all false.
-> A, B, C, D, and F are incorrect based on the above.

11. Given:
class Feline {
public static void main(String[] args) {
Long x = 42L;
Long y = 44L;
System.out.print(" " + 7 + 2 + " ");
System.out.print(foo() + x + 5 + " ");
System.out.println(x + y + foo());
}
static String foo() { return "foo"; }
}
What is the result?
A. 9 foo47 86foo
B. 9 foo47 4244foo
C. 9 foo425 86foo
D. 9 foo425 4244foo
E. 72 foo47 86foo
F. 72 foo47 4244foo
G. 72 foo425 86foo
H. 72 foo425 4244foo
I. Compilation fails.
Answer:
-> G is correct. Concatenation runs from left to right, and if either operand is a String, the operands are concatenated. If both operands are numbers they are added together. Unboxing works in conjunction with concatenation.
-> A, B, C, D, E, F, H, and I are incorrect based on the above.

12. Place the fragments into the code to produce the output 33. Note, you must use each fragment exactly once.
CODE:
class Incr {
public static void main(String[] args) {
Integer x = 7;
int y = 2;
x ___ ___;
___ ___ ___;
___ ___ ___;
___ ___ ___;
System.out.println(x);
}
}

FRAGMENTS:

Answer:
class Incr {
public static void main(String[] args) {
Integer x = 7;
int y = 2;
x *= x;
y *= y;
y *= y;
x -= y;
System.out.println(x);
}
}
Yeah, we know it’s kind of puzzle-y, but you might encounter something like it on the real exam.

Page: 2

1 2 3 4 5
  <<Back To SCJP Material Main Page



freshers jobs | fresher jobs | freshers job | fresher job | fresher it jobs | sap fresher jobs | jobs for fresher | jobs for freshers | it jobs for freshers | abap fresher jobs | net jobs for freshers | net fresher jobs | net freshers jobs | freshers job sites | fresher job openings | software jobs for freshers | fresher jobs bangalore | hr jobs for freshers | software testing jobs for freshers | fresher jobs india | fresher jobs chennai | fresher it job | freshers it jobs | mba fresher jobs | hr fresher jobs | fresher jobs in india | networking jobs for freshers | testing jobs for freshers | job for fresher | oracle fresher jobs | mca fresher jobs | sap freshers jobs | jobs for mca freshers | fresher jobs hyd | freshers software jobs | it job for freshers | fresher job sites | jobs for mba freshers | freshers job it | hot jobs for freshers | job for freshers | testing fresher jobs | mainframe fresher jobs | jobs for freshers sap | fresher jobs at | fresher jobs usa | jobs for freshers at | jobs for freshers usa | freshers jobs at | freshers jobs usa | tech freshers jobs | net freshers job | software fresher jobs | job opportunities for freshers | jobs for freshers in usa | job vacancies for freshers | jobs mumbai fresher | it jobs for fresher | freshers job openings | job openings for freshers | it jobs for freshers in | freshers jobs bangalore | freshers job india | freshers jobs india | jobs in pune for freshers | jobs for fresher in | fresher jobs in usa | net fresher jobs in | fresher jobs in | fresher job in usa | jobs for freshers in | qa jobs for freshers | fresher jobs in dubai | freshers jobs in usa | job opening for freshers | hr freshers job | freshers job in usa | job openings for freshers in | fresher it jobs in | freshers it jobs in | job for fresher in | job for freshers in | testing jobs for freshers in | sap jobs for freshers in | sap freshers jobs in | sap fresher jobs in | mba freshers jobs | jobs for freshers in delhi | jobs for freshers in mumbai | freshers jobs in delhi | fresher jobs in mumbai | fresher jobs in bangalore | fresher jobs in delhi | net jobs for freshers in | fresher jobs in hyderabad | mba freshers job | freshers job in bangalore | fresher hr jobs in | fresher job in | jobs freshers in | finance jobs for freshers | hr jobs for freshers in | jobs in dubai for freshers | fresher it jobs in bangalore | freshers job in india | freshers job in | software jobs for freshers in | mba fresher job | fresher software jobs in | software testing jobs for freshers in | freshers jobs in mumbai | fresher jobs in chennai | mba fresher jobs in | mba finance fresher jobs | jobs for mba freshers in | jobs for mba fresher | mba freshers jobs in | fresher jobs hyderabad | hr freshers jobs | fresher jobs in pune | freshers jobs in pune | freshers jobs in chennai | jobs for mba finance fresher | freshers job in chennai | jobs for mba finance freshers | finance fresher jobs | jobs for freshers in hyderabad | freshers jobs in hyderabad | jobs for freshers in bangalore | freshers jobs in india | jobs for freshers in chennai | jobs for freshers in india | instrumentation jobs for freshers | freshers jobs in bangalore | engineering jobs for freshers in | job for mba fresher | mechanical fresher jobs | mca freshers jobs | jobs for bca freshers | b tech freshers jobs | sap jobs for fresher | sap abap fresher jobs | job sites for freshers | fresher | jobs | bpo jobs | freshers | careers freshers | freshers it | it jobs | fresher world | mba jobs | j2ee jobs | fresher recruitment | call center jobs | testing jobs | finance jobs | call centre jobs | networking jobs | wipro jobs | hyderabad jobs | chennai jobs | fresher opening | pune jobs | telecom jobs | fresher openings | banglore jobs | bangalore jobs | mca jobs | tcs jobs | kolkata jobs | it fresher | mba fresher | fresher india | gurgaon jobs | hr jobs | noida jobs | india jobs | mumbai jobs | fresh graduates | delhi jobs | freshers recruitment | consultant jobs | engineer jobs | engineering jobs | sap jobs | parttime job | walkin jobs | internet jobs | data entry jobs | jobs career | local jobs | online jobs | parttime jobs | online part time job | technical support jobs | net jobs | jobs at | software jobs | website jobs

Home   |   About Us   |   Contact Us
Copyright @ durgasoft.com