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

10. Java.lang Package

Question: 11
Given:
11. public String makinStrings() {
12. String s = “Fred”;
13. s = s + “47”;
14. s = s.substring(2, 5);
15. s = s.toUpperCase();
16. return s.toString();
17. }
How many String objects will be created when this method is invoked?
A. 1                          B. 2
C. 3                           D. 4
E. 5                            F. 6
Answer: E

12. Which statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden? (Choose all that apply.)
A. If the equals() method returns true, the hashCode() comparison == might return false.
B. If the equals() method returns false, the hashCode() comparison == might return true.
C. If the hashCode() comparison == returns true, the equals() method must return true.
D. If the hashCode() comparison == returns true, the equals() method might return true.
E. If the hashCode() comparison != returns true, the equals() method might return true.
Answer:
- > B and D. B is true because often two dissimilar objects can return the same hashcode value.
D is true because if the hashCode() comparison returns ==, the two objects might
or might not be equal.
->A, C, and E are incorrect. C is incorrect because the hashCode() method is very flexible in its return values, and often two dissimilar objects can return the same hash code value. A and E are a negation of the hashCode() and equals() contract.

13. Given:
1. class Convert {
2. public static void main(String[] args) {
3. Long xL = new Long(456L);
4. long x1 = Long.valueOf("123");
5. Long x2 = Long.valueOf("123");
6. long x3 = xL.longValue();
7. Long x4 = xL.longValue();
8. Long x5 = Long.parseLong("456");
9. long x6 = Long.parseLong("123");
10. }
11. }
Which will compile using Java 5, but will NOT compile using Java 1.4? (Choose all that apply.)
A. Line 4.
B. Line 5.
C. Line 6.
D. Line 7.
E. Line 8.
F. Line 9.
Answer:
-> A, D, and E are correct. Because of the methods’ return types, these method calls required
autoboxing to compile.
-> B, C, and F are incorrect based on the above. (Objective 3.1)

14. Given:
class TKO {
public static void main(String[] args) {
String s = "-";
Integer x = 343;
long L343 = 343L;
if(x.equals(L343)) s += ".e1 ";
if(x.equals(343)) s += ".e2 ";
Short s1 = (short)((new Short((short)343)) / (new Short((short)49)));
if(s1 == 7) s += "=s ";
if(s1 < new Integer(7+1)) s += "fly ";
System.out.println(s);
} }
Which of the following will be included in the output String s? (Choose all that apply.)
A. .e1                                              B. .e2
C. =s                                               D. fly
E. None of the above.                     F. Compilation fails.
G. An exception is thrown at runtime.
Answer:
- > B , C, and D are correct. Remember, that the equals() method for the integer wrappers
will only return true if the two primitive types and the two values are equal. With C, it's okay to unbox and use ==. For D, it's okay to create a wrapper object with an expression, and unbox it for comparison with a primitive.
-> A, E, F, and G are incorrect based on the above. (Remember that A is using the equals() method to try to compare two different types.) (Objective 3.1)

15. Which about the three java.lang classes String, StringBuilder, and StringBuffer are true? (Choose all that apply.)
A. All three classes have a length() method.
B. Objects of type StringBuffer are thread-safe.
C. All three classes have overloaded append() methods.
D. The "+" is an overloaded operator for all three classes.
E. According to the API, StringBuffer will be faster than StringBuilder under most
implementations.
F. The value of an instance of any of these three types can be modified through various
methods in the API.

Answer:
-> A and B are correct.
-> C is incorrect because String does not have an "append" method. D is incorrect because only String objects can be operated on using the overloaded "+" operator. E is backwards, StringBuilder is typically faster because it's not thread-safe. F is incorrect because String objects are immutable. A String reference can be altered to refer to a different String object, but the objects themselves are immutable. (Objective 3.1)

16. Given:
class Polish {
public static void main(String[] args) {
int x = 4;
StringBuffer sb = new StringBuffer("..fedcba");
sb.delete(3,6);
sb.insert(3, "az");
if(sb.length() > 6) x = sb.indexOf("b");
sb.delete((x-3), (x-2));
System.out.println(sb);
}
}
What is the result?
A. .faza    
B. .fzba
C. ..azba
D. .fazba
E. ..fezba
F. Compilation fails.
G. An exception is thrown at runtime.

Answer:
-> C is correct. Remember that StringBuffer methods use zero-based indexes, and that
ending indexes are typically exclusive.
-> A, B, D, E, F, and G are incorrect based on the above. (Objective 3.1)

Page: 3

1 2 3
  <<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