Java - Lang Package
Java - Lang Package
Java - Lang Package
A. return super.hashCode();
B. return name.hashCode() + age * 7;
C. return name.hashCode() + comment.hashCode() / 2;
D. return name.hashCode() + comment.hashCode() / 2 - age * 3;
Answer: B
Q: 03 Given:
11. public void testIfA() {
12. if (testIfB("True")) {
13. System.out.println("True");
14. } else {
15. System.out.println("Not true");
16. }
DURGASOFT, # 202,2nd Floor,HUDA Maitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com Page 2
DURGA’s SCJP Material
17. }
18. public Boolean testIfB(String str) {
19. return Boolean.valueOf(str);
20. }
What is the result when method testIfA is invoked?
A. True
B. Not true
C. An exception is thrown at runtime.
D. Compilation fails because of an error at line 12.
E. Compilation fails because of an error at line 19.
Answer: A
Q: 04 Given:
1. public class Boxer1{
2. Integer i;
3. int x;
4. public Boxer1(int y) {
5. x = i+y;
6. System.out.println(x);
7. }
8. public static void main(String[] args) {
9. new Boxer1(new Integer(4));
10. }
11. }
What is the result?
Q: 05 Given:
1. public class TestString3 {
2. public static void main(String[] args) {
3. // insert code here
5. System.out.println(s);
6. }
7. }
Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose
two.)
A. String s = "123456789";
s = (s-"123").replace(1,3,"24") - "89";
B. StringBuffer s = new StringBuffer("123456789");
s.delete(0,3).replace(1,3,"24").delete(4,6);
C. StringBuffer s = new StringBuffer("123456789");
Q: 06 Given:
Q: 07 Given:
Answer: B
Q: 08 Which two statements are true about the hashCode method? (Choose two.)
A. The hashCode method for a given class can be used to test for object equality and object inequality
for that
class.
B. The hashCode method is used by the java.util.SortedSet collection class to order the elements within
that set.
C. The hashCode method for a given class can be used to test for object inequality, but NOT object
equality, for
that class.
D. The only important characteristic of the values returned by a hashCode method is that the
distribution of
values must follow a Gaussian distribution.
E. The hashCode method is used by the java.util.HashSet collection class to group the elements within
that set
into hash buckets for swift retrieval.
Answer: C, E
Q: 12 Given:
22. StringBuilder sb1 = new StringBuilder("123");
23. String s1 = "123";
24. // insert code here
25. System.out.println(sb1 + " " + s1);
Which code fragment, inserted at line 24, outputs "123abc 123abc"?
A. sb1.append("abc"); s1.append("abc");
B. sb1.append("abc"); s1.concat("abc");
C. sb1.concat("abc"); s1.append("abc");
D. sb1.concat("abc"); s1.concat("abc");
E. sb1.append("abc"); s1 = s1.concat("abc");
F. sb1.concat("abc"); s1 = s1.concat("abc");
G. sb1.append("abc"); s1 = s1 + s1.concat("abc");
H. sb1.concat("abc"); s1 = s1 + s1.concat("abc");
Answer: E
Q: 13 Given:
1. public class BuildStuff {
2. public static void main(String[] args) {
Q: 15 Given:
Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder
object? (Choose two.)
A. When using versions of Java technology earlier than 5.0.
B. When sharing a StringBuffer among multiple threads.
C. When using the java.io class StringBufferInputStream.
D. When you plan to reuse the StringBuffer to build more than one string.
Answer: A,B