SCJP Questions

SCWCD Questions

Friday, April 10, 2009

Free SCJP Mock Exam Links

Free SCJP Mock Exams and Practice Exams




  1. Java Ranch SCJP Links


  2. Cert Champ scjp 1.5 and scjp 1.6 Mock Exam



  3. Java
    Programmer Exam Simulator for 1.4 (310-035) Exam by Marcus Green (60
    questions)



  4. SCJP Mock Test for 1.5 and 1.6


  5. Java
    Programmer Certification Mock Exam No 1 by Marcus Green (60 questions)


  6. Java
    Programmer Certification Mock Exam No 2 by Marcus Green (60 questions)



  7. SCJP Mock Test for 1.5 and 1.6


  8. Java
    Programmer Certification Mock Exam No 3 by Marcus Green (60 questions)


  9. Java
    Programmer Certification Exam 1.4 (310-035) by Dan Chisholm (569 questions)

  10. ePractice
    Sample Questions for 1.4 (310-035) Exam by Sun (10 questions)

  11. ePractice
    Sample Questions for 1.2 (310-025) Exam by Sun (10 questions)

  12. Java
    Certification Mock Exam by John Hunt (65 questions)

  13. SCJP
    Mock Exams for 1.4 (310-035) Exam by JDiscuss.com (135 Questions)

  14. SCJP
    Mock Exams for 1.2 (310-025) Exam by JDiscuss.com (135 Questions)

  15. SCJP
    Mock Exam for 1.2 (310-025) Exam by Ashok Kumar Gupta (39 Questions)

  16. Mock
    Exams for 1.2 (310-025)/1.4 (310-035) Exams for Java Certification by
    Jiris.com (244 Questions)

  17. Java
    5 (310-055) SCJP questions by Kathy Sierra and Bert Bates (11 Qustions)

  18. Mock
    Exams for 1.2 (310-025)/1.4 (310-035) Exams by W. B. Brogden (141 Questions)

  19. MindQ's
    Sun Certified Java Programmer Practice Test (60 Questions)

  20. Mock
    exam engine for 1.4 (310-035) Exam by Khalid A. Mughal and Rolf W. Rasmussen
    (61 Questions)

  21. Mock
    Exam by Sreenivasa Kumar Majji (30 Questions)

  22. Java
    5 (310-055) SCJP Mock Exam by Javabeat.net (14 Questions)

  23. Jxam
    by Eddie Mcnally (200 Questions)

  24. Questions
    from The Complete Java 2 Certification Study Guide (10 Questions)

  25. SCJP
    Mock Questions by Abhilash Koneri (80 Questions)

  26. Mock
    Exam by Amit Poddar (42 Questions)

  27. Sun
    Certified Programmer Practice Exam by Barry Boone Part I (1 - 19 Questions)

  28. Sun
    Certified Programmer Practice Exam by Barry Boone Part II (20 - 39 Questions)

  29. Sun
    Certified Programmer Practice Exam by Barry Boone Part III (40 - 70
    Questions)

  30. JDCert
    Mock Exam (131 Questions)

  31. SCJP
    Mock Exam by Sarga (27 Questions)

  32. SCJP
    Questions Part I collected by BMC88 (30 Questions)

  33. SCJP
    Questions Part II collected by BMC88 (30 Questions)

  34. SCJP
    Questions Part III collected by BMC88 (30 Questions)

  35. SCJP
    Questions Part IV collected by BMC88 (10 Questions)

  36. SCJP
    Questions Part I by BMC88 (10 Questions)

  37. SCJP
    Questions Part II by BMC88 (10 Questions)

  38. SCJP
    Questions Part III by BMC88 (7 Questions)

  39. SCJP2
    Mock Exam 1 by javaprepare.com (59 Questions)

  40. SCJP2
    Mock Exam 2 by javaprepare.com (38 Questions)

  41. Sample
    questions by topic for Java Certification by javaprepare.com (130 Questions)

  42. Java
    Certificatoin Exam by SinoTex (60 Questions)

  43. JQPlus
    Trial for SCJP 1.4 (310-035) Exam by EnthuWare (59 Questions)

  44. JQPlus
    Trial for SCJP 1.2 (310-025) Exam by EnthuWare (60 Questions)

  45. SCJP
    1.4 (310-035) Practice Exam by Whizlabs (29 Questions)

  46. Mock
    Test for SCJP2 by Yogesh Shastri (29 Questions)

  47. Mock
    Exam Engine for SCJP by Ashish Hareet (373 Questions)

  48. SCJP
    1.4 (310-035) Demo Mock Exam by javacertificate.com (10 Questions)

  49. Whizlabs
    SCJP 5.0 (310-055) Exam Simulator Trial Version (87 Questions)

  50. Whizlabs
    SCJP 1.4 (310-035) Exam Simulator Trial Version (70 Questions)

  51. The
    JavaRanch Rules Round-up Game (144 Questions)

  52. SCJP
    1.4 (310-035) Practice Exam by ExamCram (30 Questions)

  53. SCJP
    1.2 (310-025) Practice Exam by ExamCram (59 Questions)

  54. Sun
    Certified Programmer Practice Exam by Levteck.com (70 Questions)

  55. SCJP
    Practice Questions by Anil Bachi (67 Questions)

  56. Questions
    for SCJP Exam by CertCities.com (30 Questions)

  57. Test
    Your Knowledge of Java Topics by CertMag.com (8 Questions)

  58. SCJP
    1.4 (310-055) Practice Tests by Giri Mandalika (268 Questions)

  59. SCJP
    Mock Exam 1 by go4java (59 Questions)

  60. SCJP
    Mock Exam 2 by go4java (59 Questions)

  61. Mock
    Test by Debashish Chakrabarty (12 Questions)

  62. Java
    Programming Assessment Test by javacamp.org (20 Questions)

  63. Sun
    Java 2 Programmer Mock Exam by Natarajan Meghanathan (59 Questions)

  64. Mock
    Test by Sahir Shah (100 Questions)

  65. SCJP
    Mock Exam by Valentin Crettaz (59 Questions)

  66. Java2
    Certification Mock Exam by Siva Valiveru and Girija Valiveru (60 Questions)

  67. Interactive
    Java Exam by tipsmart.com (27 Questions)

  68. Sun
    Certified Java Programmer Practice Questions by 4Tests.com (40 Questions)

  69. JSCP
    1.4 Practice Questions by simulationexams.com (10 Questions)

  70. J2
    Exam Simulator by universalteacherpublications.com (600 Questions)

  71. SCJP
    Mock Exam by rraje_2000 (60 Questions)

  72. Test
    Your Java Knowledge by Richard Baldwin (130 Questions)

  73. Java
    5 Basic Exam by JavaBlackBelt.com (40 Questions)

  74. Java
    SE Intermediate Exam by JavaBlackBelt.com (40 Questions)

  75. Certification
    Exam Tool by IBM (30 Questions)

  76. The SCJP Exam Challenge by zindell (118 Questions)

Free SCWCD Mock Exam Links

Free SCWCD Mock Exams and Practice Exams



  1. Sun
    Certified Web Component Developer Mock Exam by JavaRanch (69 questions)

  2. Attend SCWCD before final exam


  3. SCWCD 1.5
    Mock Exam 100 questions by CertChamp




  4. Sun
    Certified Web Component Developer for J2EE - Exam CX-310-080 by ExamCram
    (30 questions)

  5. SCWCD 1.5
    Mock Exam 120 questions

  6. Sample
    questions by topic for SCWCD Certification by javaprepare.com (60 questions)

  7. Web
    Component Developer Exam by Eduardo Cobian (60 questions)

  8. SCWCD
    Mock Exam by Anand Chawla (59 questions)

  9. SCWCD
    Mock Tests by JDiscuss.com (285 questions)

  10. SCWCD
    Mock Exams by j2eecertificate.com (90 questions)

  11. SCWCD
    Preparation Kit Trial Version by Whizlabs (80 questions)

  12. JWebPlus
    V4 Trial Version by Enthuware (20 questions)

  13. SCWCD
    Mock Exam on JPilotTest Exam Simulator by S.M.Rahman (59 questions)

  14. ePractice
    Sample Questions for SCWCD for the J2EE 1.3 ( questions)

  15. ePractice
    Sample Questions for SCWCD for the J2EE 1.4 ( questions)

  16. SCWCD
    Mock Exam by Jiris.com (50 questions)

  17. SCWCD 5.0
    Mock Exam


  18. Books you can refer



    Head First Servlets and JSP

    |
    Sun Certified Web Component Developer Study Companion: SCWCD Java EE 5 (exams 310-083 and 310-084)

    |
    Professional SCWCD Certification







Free SCJP Mock Exam Links

Free SCJP Mock Exams and Practice Exams




  1. Java Ranch SCJP Links


  2. Cert Champ scjp 1.5 and scjp 1.6 Sample Questions



  3. Java
    Programmer Exam Simulator for 1.4 (310-035) Exam by Marcus Green (60
    questions)



  4. SCJP Mock Test for 1.5 and 1.6


  5. Java
    Programmer Certification Mock Exam No 1 by Marcus Green (60 questions)


  6. Books you can refer



    SCJP 6 Exam 310-065
    |
    SCJP (Exam 310-055)
    |
    A Programmer's Guide to Java SCJP Certification
    |
    Programmer's Guide to Java SCJP Certification, A: A Comprehensive Primer, 3/e
    |
    SCJP book

  7. Java
    Programmer Certification Mock Exam No 2 by Marcus Green (60 questions)



  8. SCJP Mock Test for 1.5 and 1.6


  9. Java
    Programmer Certification Mock Exam No 3 by Marcus Green (60 questions)


  10. Java
    Programmer Certification Exam 1.4 (310-035) by Dan Chisholm (569 questions)

  11. ePractice
    Sample Questions for 1.4 (310-035) Exam by Sun (10 questions)

  12. ePractice
    Sample Questions for 1.2 (310-025) Exam by Sun (10 questions)

  13. Java
    Certification Mock Exam by John Hunt (65 questions)

  14. SCJP
    Mock Exams for 1.4 (310-035) Exam by JDiscuss.com (135 Questions)

  15. SCJP
    Mock Exams for 1.2 (310-025) Exam by JDiscuss.com (135 Questions)

  16. SCJP
    Mock Exam for 1.2 (310-025) Exam by Ashok Kumar Gupta (39 Questions)

  17. Mock
    Exams for 1.2 (310-025)/1.4 (310-035) Exams for Java Certification by
    Jiris.com (244 Questions)

  18. Java
    5 (310-055) SCJP questions by Kathy Sierra and Bert Bates (11 Qustions)

  19. Mock
    Exams for 1.2 (310-025)/1.4 (310-035) Exams by W. B. Brogden (141 Questions)

  20. MindQ's
    Sun Certified Java Programmer Practice Test (60 Questions)

  21. Mock
    exam engine for 1.4 (310-035) Exam by Khalid A. Mughal and Rolf W. Rasmussen
    (61 Questions)

  22. Mock
    Exam by Sreenivasa Kumar Majji (30 Questions)

  23. Java
    5 (310-055) SCJP Mock Exam by Javabeat.net (14 Questions)

  24. Jxam
    by Eddie Mcnally (200 Questions)

  25. Questions
    from The Complete Java 2 Certification Study Guide (10 Questions)

  26. SCJP
    Mock Questions by Abhilash Koneri (80 Questions)

  27. Mock
    Exam by Amit Poddar (42 Questions)

  28. Sun
    Certified Programmer Practice Exam by Barry Boone Part I (1 - 19 Questions)

  29. Sun
    Certified Programmer Practice Exam by Barry Boone Part II (20 - 39 Questions)

  30. Sun
    Certified Programmer Practice Exam by Barry Boone Part III (40 - 70
    Questions)

  31. JDCert
    Mock Exam (131 Questions)

  32. SCJP
    Mock Exam by Sarga (27 Questions)

  33. SCJP
    Questions Part I collected by BMC88 (30 Questions)

  34. SCJP
    Questions Part II collected by BMC88 (30 Questions)

  35. SCJP
    Questions Part III collected by BMC88 (30 Questions)

  36. SCJP
    Questions Part IV collected by BMC88 (10 Questions)

  37. SCJP
    Questions Part I by BMC88 (10 Questions)

  38. SCJP
    Questions Part II by BMC88 (10 Questions)

  39. SCJP
    Questions Part III by BMC88 (7 Questions)

  40. SCJP2
    Mock Exam 1 by javaprepare.com (59 Questions)

  41. SCJP2
    Mock Exam 2 by javaprepare.com (38 Questions)

  42. Sample
    questions by topic for Java Certification by javaprepare.com (130 Questions)

  43. Java
    Certificatoin Exam by SinoTex (60 Questions)

  44. JQPlus
    Trial for SCJP 1.4 (310-035) Exam by EnthuWare (59 Questions)

  45. JQPlus
    Trial for SCJP 1.2 (310-025) Exam by EnthuWare (60 Questions)

  46. SCJP
    1.4 (310-035) Practice Exam by Whizlabs (29 Questions)

  47. Mock
    Test for SCJP2 by Yogesh Shastri (29 Questions)

  48. Mock
    Exam Engine for SCJP by Ashish Hareet (373 Questions)

  49. SCJP
    1.4 (310-035) Demo Mock Exam by javacertificate.com (10 Questions)

  50. Whizlabs
    SCJP 5.0 (310-055) Exam Simulator Trial Version (87 Questions)

  51. Whizlabs
    SCJP 1.4 (310-035) Exam Simulator Trial Version (70 Questions)

  52. The
    JavaRanch Rules Round-up Game (144 Questions)

  53. SCJP
    1.4 (310-035) Practice Exam by ExamCram (30 Questions)

  54. SCJP
    1.2 (310-025) Practice Exam by ExamCram (59 Questions)

  55. Sun
    Certified Programmer Practice Exam by Levteck.com (70 Questions)

  56. SCJP
    Practice Questions by Anil Bachi (67 Questions)

  57. Questions
    for SCJP Exam by CertCities.com (30 Questions)

  58. Test
    Your Knowledge of Java Topics by CertMag.com (8 Questions)

  59. SCJP
    1.4 (310-055) Practice Tests by Giri Mandalika (268 Questions)

  60. SCJP
    Mock Exam 1 by go4java (59 Questions)

  61. SCJP
    Mock Exam 2 by go4java (59 Questions)

  62. Mock
    Test by Debashish Chakrabarty (12 Questions)

  63. Java
    Programming Assessment Test by javacamp.org (20 Questions)

  64. Sun
    Java 2 Programmer Mock Exam by Natarajan Meghanathan (59 Questions)

  65. Mock
    Test by Sahir Shah (100 Questions)

  66. SCJP
    Mock Exam by Valentin Crettaz (59 Questions)

  67. Java2
    Certification Mock Exam by Siva Valiveru and Girija Valiveru (60 Questions)

  68. Interactive
    Java Exam by tipsmart.com (27 Questions)

  69. Sun
    Certified Java Programmer Practice Questions by 4Tests.com (40 Questions)

  70. JSCP
    1.4 Practice Questions by simulationexams.com (10 Questions)

  71. J2
    Exam Simulator by universalteacherpublications.com (600 Questions)

  72. SCJP
    Mock Exam by rraje_2000 (60 Questions)

  73. Test
    Your Java Knowledge by Richard Baldwin (130 Questions)

  74. Java
    5 Basic Exam by JavaBlackBelt.com (40 Questions)

  75. Java
    SE Intermediate Exam by JavaBlackBelt.com (40 Questions)

  76. Certification
    Exam Tool by IBM (30 Questions)

  77. The SCJP Exam Challenge by zindell (118 Questions)

SCJP Mock Questions : Autoboxing and unboxing

********************************************************************
original from www.techfaq360.com
SCJP Mock Questions : Autoboxing/unboxing
********************************************************************
Question No :1
What is output of the code bellow ?
public class Test {
public static void main(String[] args) {
List list = new ArrayList();
list.add(0, 59);
int total = list.get(0);
System.out.println(total);
}
}
(Choose correct one from multiple below)
1. Compile time error, because you have to do
int total = ((Integer)(list.get(0))).intValue();
2. 59
3. Runtime Exceptions
4. None of the above
correct is :2
Explanations :Manual conversion between primitive types (such as an int) and wrapper classes
(such as Integer) is necessary when adding a primitive data type to a collection in jdk1.4 but
The new autoboxing/unboxing feature eliminates this manual conversion in jdk 1.5
------------------------------------------------------------------------------
Question No :2
What is the output of the bellow code?
public class Test {
public static void main(String[] args) {
Boolean expr = true;
if (expr) {
System.out.println("true");
} else {
System.out.println("false");
}
}
}
(Choose correct one from multiple below)
1. true
2. Compile with error because you can't use Boolean object in if()
3. Runtime Exception
4. None of the above
correct is :1
Explanations :In the if statement, condition can be Boolean in jdk1.5
------------------------------------------------------------------------------
Question No :3
Is the bellow code compile without error ?
public class Test {
public static void main(String[] args) {
Boolean expr = true;
while (expr) {
expr = !expr;
}
}
}
(Choose correct one from multiple below)
1. No, while condition can't allow Boolean object, it allows boolean primitive type
2. Yes, while condition allow Boolean object
3. Can't say
4. None of the above
correct is :2
Explanations :In the while, do-while and for statements, the condition can be Boolean
------------------------------------------------------------------------------
Question No :4
What is the output for the bellow code ?
public class Test {
public static void main(String[] args) {
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
Map m = new TreeMap();
for (String word : words) {
Integer freq = m.get(word);
m.put(word, freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
(Choose correct one from multiple below)
1. {aaa=2, bbb=1, ccc=1}
2. Compile with Error
3. Runtime Exception
4. None of the above
correct is :1
Explanations :Boxing and unboxing in collections
------------------------------------------------------------------------------
Question No :5
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
which bellow statement is same as
for (int i=0;i(Choose correct one from multiple below)
1. for (String word : words)
2. for (String word : words.length)
3. Can't say
4. None of the above
correct is :1
Explanations :for (int i=0;ifor (String word : words) in jdk 1.5
------------------------------------------------------------------------------
Question No :6
public class Test {
public static void main(String[] args) {
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
Map m = new TreeMap();
for (int i=0;iInteger freq = m.get(words[i]);
m.put(words[i], freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
is same as ?
(Choose correct one from multiple below)
1. public class Test {
public static void main(String[] args) {
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
Map m = new TreeMap();
for (String word : words) {
Integer freq = m.get(word);
m.put(word, freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
2. public class Test {
public static void main(String[] args) {
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
Map m = new TreeMap();
for (String word : words.length) {
Integer freq = m.get(word);
m.put(word, freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
3. public class Test {
public static void main(String[] args) {
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
Map m = new TreeMap();
for (String word : words) {
Integer freq = m.get(word[i]);
m.put(word[i], freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
4. None of the above
correct is :1
Explanations :public class Test {
public static void main(String[] args) {
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
Map m = new TreeMap();
for (int i=0;iInteger freq = m.get(words[i]);
m.put(words[i], freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
is same as
public class Test {
public static void main(String[] args) {
String[] words = new String[] {"aaa", "bbb", "ccc", "aaa"};
Map m = new TreeMap();
for (String word : words) {
Integer freq = m.get(word);
m.put(word, freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
------------------------------------------------------------------------------
Question No :7
ArrayList list = new ArrayList();
list.add(0, new Integer(42));
int total = (list.get(0)).intValue();
is same as in jdk1.5 is?
(Choose correct one from multiple below)
1. ArrayList list = new ArrayList();
list.add(0, 42);
int total = list.get(0);
2. ArrayList list = new ArrayList();
list.add(0, 42);
int total = (int)list.get(0);
3. ArrayList list = new ArrayList();
list.add(0, 42);
int total = list.get(0).int();
4. None of the above
correct is :1
Explanations :In JDK 1.5 Don't need to cast
------------------------------------------------------------------------------
Question No :8
What is the output of the bellow code ?
public class Test {
public static void main(String[] args) {
Integer in = new Integer(null);
System.out.println(in.intValue());
}
}
(Choose correct one from multiple below)
1. 0
2. Compile with error because , Integer in = new Integer(null);
3. java.lang.NumberFormatException
4. None of the above
correct is :3
Explanations :An Integer expression can have a null value. If your program tries to autounbox null,
it will throw a NullPointerException
------------------------------------------------------------------------------
Question No :9
What is the output of bellow code ?
public class Test {
public static void main(String[] args) {
Integer i5 = new Integer(5);
Integer j5 = new Integer(5);
if(i5 == j5){
System.out.println("equal");
}else{
System.out.println("false");
}
}
}
(Choose correct one from multiple below)
1. true
2. false
3. Compile with error
4. None of the above
correct is :2
Explanations :checks references , so both are different
------------------------------------------------------------------------------
Question No :10
What is the output of the bellow code?
public class Test {
public static void main(String[] args) {
Integer i5 = new Integer(5);
Integer j5 = new Integer(5);
if(i5.equals(j5)){
System.out.println("equal");
}else{
System.out.println("false");
}
}
}
(Choose correct one from multiple below)
1. equal
2. false
3. Compile with error
4. None of the above
correct is :1
Explanations :checks for content
------------------------------------------------------------------------------
Question No :11
What is the output?
public class Test {
public static void main(String[] args) {
Integer i5 = 2;
Integer j5 = 2;
System.out.println(i5 == j5);
if(i5 == j5){
System.out.println("equal");
}else{
System.out.println("not equal");
}
}
}
(Choose correct one from multiple below)
1. false
not equal
2. true
not equal
3. true
equal
4. None of the above
correct is :1
Explanations :No Explanations
------------------------------------------------------------------------------
Question No :12
What is the output ?
public class Test {
public static void main(String[] args) {
Short expr = 1;
switch (expr) {
case 1:
System.out.println("ONE"); break;
case 2:
System.out.println("TWO"); break;
case 3:
System.out.println("THREE"); break;
default:
assert false;
}
}
}
(Choose correct one from multiple below)
1. ONE
2. Compile With error because you can't use sort in switch.
3. Runtime Exceptions
4. None of the above
correct is :1
Explanations :In the switch statement, the switch expression can be Character, Byte, Short or
Integer in JDK 1.5
------------------------------------------------------------------------------
Question No :13
What is the output ?
public class Test {
public static void main(String[] args) {
Integer i = null;
int j = i;
System.out.println(j);
}
}
(Choose correct one from multiple below)
1. 0
2. null
3. Compile with error
4. java.lang.NullPointerException
correct is :4
Explanations :trying to outbox null
------------------------------------------------------------------------------
Question No :14
What is the output of the bellow code ?
public class Test {
public static void main(String[] args) {
doSomething(1);
doSomething(2.0);
}
public static void doSomething(double num) {
System.out.println("double : " + num);
}
public static void doSomething(Integer num) {
System.out.println("Integer : " + num);
}
}
(Choose correct one from multiple below)
1. double : 1.0
double : 2.0
2. Integer : 1
double : 2.0
3. Integer : 1
Integer : 2
4. None of the above
correct is :1
Explanations :No Explanation avilable
------------------------------------------------------------------------------
Question No :15
What is the output ?
public class Test {
public static void main(String[] args) {
Integer i=1;
doSomething(i);
doSomething(2.0);
}
public static void doSomething(double num) {
System.out.println("double : " + num);
}
public static void doSomething(Integer num) {
System.out.println("Integer : " + num);
}
}
(Choose correct one from multiple below)
1. Integer : 1
double : 2.0
2. double : 1.0
double : 2.0
3. double : 1.0
Integer: 2
4. None of the above
correct is :1
Explanations :No Explanation
------------------------------------------------------------------------------
Question No :16
What is the output?
public class Test {
public static void main(String[] args) {
Character c1 = '\u0000';
Character c2 = '\u0000';
System.out.println("c1 == c2 : " + (c1 == c2));
}
}
(Choose correct one from multiple below)
1. c1 == c2 : true
2. c1 == c2 : false
3. Compile with error
4. None of the above
correct is :1
Explanations :No Exp
------------------------------------------------------------------------------
Question No :17
What is the output?
public class Test {
public static void main(String[] args) {
Character c11 = '\u00FF';
Character c12 = '\u00FF';
System.out.println("c11 == c12 : " + (c11 == c12));
}
}
(Choose correct one from multiple below)
1. c11 == c12 : false
2. c11 == c12 : true
3. Compile with error
4. None of the above
correct is :1
Explanations :Character can be check by == but the value range of Character '\u0000' to '\u007F'.
u00FF is crossed the range.
------------------------------------------------------------------------------
Question No :18
What is true about StringBuilder ?
(Choose correct one from multiple below)
1. StringBuilder is a drop-in replacement for StringBuffer in cases where thread safety is not an
issue.
2. StringBuilder is NOT synchronized
3. StringBuilder offers FASTER performance than StringBuffer
4. All of the above
correct is :4
Explanations :J2SE5.0 added the StringBuilder class, which is a drop-in replacement for
StringBuffer in cases where thread safety is not an issue. Because StringBuilder is NOT
synchronized, it offers FASTER performance than StringBuffer.
------------------------------------------------------------------------------
Question No :19
Which statement is true ?
(Choose correct one from multiple below)
1. Instances of StringBuilder are not safe for use by multiple threads
2. Instances of StringBuilder are safe for use by multiple threads
3. Both are true
4. None of the above
correct is :1
Explanations :Instances of StringBuilder are not safe for use by multiple threads. If such
synchronization is required then it is recommended that StringBuffer be used
------------------------------------------------------------------------------
Question No :20
Which statement is true about String ?
(Choose correct one from multiple below)
1. String objects are immutable, meaning that once created they cannot be altered
2. String objects are mutable, meaning that once created they can be altered
3. All of the above
4. None of the above
correct is :1
Explanations :String objects are immutable, meaning that once created they cannot be altered.
------------------------------------------------------------------------------
Question No :21
What is the output?
public class Test {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("ssss");
StringBuffer sb_2 = new StringBuffer("ssss");
System.out.println("sb equals sb_2 : " + sb.equals(sb_2));
}
}
(Choose correct one from multiple below)
1. sb equals sb_2 : false
2. sb equals sb_2 : true
3. Can't say
4. None of the above
correct is :1
Explanations :StringBuffer class DOES NOT override the equals() method. Therefore, it uses
Object class' equals(), which only checks for equality of the object references
------------------------------------------------------------------------------
Question No :22
What is the output?
public class Test {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("ssss");
String st = new String("ssss");
System.out.println("st equals sb : " + st.equals(sb));
}
}
(Choose correct one from multiple below)
1. st equals sb : false
2. st equals sb : true
3. can't say
4. None of the above
correct is :1
Explanations :String's equals() method checks if the argument if of type string, if not it returns false
------------------------------------------------------------------------------
Distribution of this pdf is illegal without permission of techfaq360.com

SCJP Mock Questions : Type Safe Enum

********************************************************************
original from www.techfaq360.com
SCJP Mock Questions : Type Safe Enum
********************************************************************
Question No :1
What will be the output of the following program?
public enum Color {
RED("Red Color"),
GREEN("Blue Color"),
BLUE("Blue Color");
private String displayName;
Color(String displayName){
this.displayName = displayName;
}
public String toString(){
return displayName;
}
}
class ColorTest{
public static void main(String[] args) {
Color redColor = Color.RED;
System.out.println(redColor);
Color blueColor = Color.BLUE;
System.out.println(blueColor);
}
}
(Choose correct one from multiple below)
1. The program will compile and throw a run-time exception
2. The program won't compile as it is not possible to define methods within an Enum.
3. The program will compile and the output will be 'Red Color' followed by 'Blue Color'.
4. None of the above
correct is :3
Explanations :defines a Enum called Color and the Enum constants within are parameterized by
defining a constructor for holding the display name of each constants. The method toString() is
defined at the declaration level which means that when an Enum object is printed, this method will
get called.
------------------------------------------------------------------------------
Question No :2
Which statement is true about enum declaration ?
(Choose correct one from multiple below)
1. can be declared at the top-level and as static enum declaration
2. implicitly static, i.e. no outer object is associated with an enum constant
3. implicitly final unless it contains constant-specific class bodies, but it can implement interfaces
4. All of the above
correct is :4
Explanations :Properties of the enum type
An enum declaration is a special kind of class declaration:
It can be declared at the top-level and as static enum declaration.
It is implicitly static, i.e. no outer object is associated with an enum constant.
It is implicitly final unless it contains constant-specific class bodies, but it can implement interfaces.
It cannot be declared abstract unless each abstract method is overridden in the constant-specific
class body of every enum constant
------------------------------------------------------------------------------
Question No :3
public class EnumTypeDeclarations {
public enum SimpleMeal {
BREAKFAST, LUNCH, DINNER
};
}
Is the above code compile without error?
(Choose correct one from multiple below)
1. true
2. false
3. Compile without error but runtime exceptions
4. None of the above
correct is :1
Explanations :Static enum declaration is OK.
------------------------------------------------------------------------------
Question No :4
public class EnumTypeDeclarations {
public void foo() {
enum SimpleMeal {
BREAKFAST, LUNCH, DINNER
}
}
}
Is the above code Compile without error ?
(Choose correct one from multiple below)
1. Compile without error
2. Compile with error
3. Compile without error but Runtime Exception
4. None of the above
correct is :2
Explanations :Local (inner) enum declaration is NOT OK!
------------------------------------------------------------------------------
Question No :5
Which statement is true about Enum constructors ?
(Choose correct one from multiple below)
1. Each constant declaration can be followed by an argument list that is passed to the constructor
of the enum type having the matching parameter signature.
2. An implicit standard constructor is created if no constructors are provided for the enum type.
3. As an enum cannot be instantiated using the new operator, the constructors cannot be called
explicitly.
4. All of the above
correct is :4
Explanations :Enum constructors
Each constant declaration can be followed by an argument list that is passed to the constructor of
the enum type having the matching parameter signature.
An implicit standard constructor is created if no constructors are provided for the enum type.
As an enum cannot be instantiated using the new operator, the constructors cannot be called
explicitly.
Example of enum constructors:
public enum Meal {
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);
private int hh;
private int mm;
Meal(int hh, int mm) {
assert (hh >= 0 && hh <= 23) : "Illegal hour.";
assert (mm >= 0 && mm <= 59) : "Illegal mins.";
this.hh = hh;
this.mm = mm;
}
public int getHour() {
return hh;
}
public int getMins() {
return mm;
}
}
------------------------------------------------------------------------------
Question No :6
What is the output of the bellow code ?
public enum Test {
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);
private int hh;
private int mm;
Test(int hh, int mm) {
assert (hh >= 0 && hh <= 23) : "Illegal hour.";
assert (mm >= 0 && mm <= 59) : "Illegal mins.";
this.hh = hh;
this.mm = mm;
}
public int getHour() {
return hh;
}
public int getMins() {
return mm;
}
public static void main(String args[]){
Test t = BREAKFAST;
System.out.println(t.getHour() +":"+t.getMins());
}
}
(Choose correct one from multiple below)
1. 7:30
2. Compile With Error
3. Compile Without Error but Runtime Exception
4. None of the above
correct is :2
Explanations :
All the enum static like BREAKFAST treat as constructor.
Enum constructors
Each constant declaration can be followed by an argument list that is passed to the constructor of
the enum type having the matching parameter signature.
An implicit standard constructor is created if no constructors are provided for the enum type.
As an enum cannot be instantiated using the new operator, the constructors cannot be called
explicitly.
Output is : 7:30
------------------------------------------------------------------------------
Question No :7
hat is the output of the bellow code ?
public enum Test {
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);
private int hh;
private int mm;
Test(int hh, int mm) {
assert (hh >= 0 && hh <= 23) : "Illegal hour.";
assert (mm >= 0 && mm <= 59) : "Illegal mins.";
this.hh = hh;
this.mm = mm;
}
public int getHour() {
return hh;
}
public int getMins() {
return mm;
}
public static void main(String args[]){
Test t = new BREAKFAST;
System.out.println(t.getHour() +":"+t.getMins());
}
}
(Choose correct one from multiple below)
1. 7:30
2. Compile with Errors
3. Runtime Exceptions
4. None of the above
correct is :2
Explanations :As an enum cannot be instantiated using the new operator, the constructors cannot
be called explicitly.
You have to do like
Test t = BREAKFAST;
------------------------------------------------------------------------------
Question No :8
What is the output ?
public enum Test {
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);
private int hh;
private int mm;
Test(int hh, int mm) {
assert (hh >= 0 && hh <= 23) : "Illegal hour.";
assert (mm >= 0 && mm <= 59) : "Illegal mins.";
this.hh = hh;
this.mm = mm;
}
public int getHour() {
return hh;
}
public int getMins() {
return mm;
}
public static void main(String args[]){
Test t = new Test(12,45);
System.out.println(t.getHour() +":"+t.getMins());
}
}
(Choose correct one from multiple below)
1. 12:45
2. Compile With Error
3. Runtime Exception
4. None of the above
correct is :2
Explanations :As an enum cannot be instantiated using the new operator, the constructors cannot
be called explicitly.
You have to do like
Test t = BREAKFAST;
------------------------------------------------------------------------------
Question No :9
Is the bellow code compile without error ?
public enum Meal {
int q = 1;
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);
private int hh;
}
(Choose correct one from multiple below)
1. Yes , compile without error
2. No, compile with error
3. compile without error but Runtime Exception
4. None of the above
correct is :2
Explanations :the enum constants must be declared before any other declarations in an enum type
public enum Meal {
int q = 1; // WRONG ! Compilation error !
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);
private int hh;
...
}
------------------------------------------------------------------------------
Question No :10
Which statement is true about Enums ?
(Choose correct one from multiple below)
1. Enums cannot declare methods which override the final methods of the java.lang.Enum class
like clone(), compareTo(Object), equals(Object) etc.
2. that the enum constants must be declared before any other declarations in an enum type.
3. both 1 and 2 is true
4. None of the above
correct is :3
Explanations :Enums cannot declare methods which override the final methods of the
java.lang.Enum class:
clone(), compareTo(Object), equals(Object), getDeclaringClass(), hashCode(), name(), ordinal().
The final methods do what their names imply, but the clone() method throws an
CloneNotSupportedException, as an enum constant cannot be cloned.
Note that the enum constants must be declared before any other declarations in an enum type.
------------------------------------------------------------------------------
Question No :11
Is the bellow code compile without error ?
public enum Meal {
BREAKFAST(7, 30) {
public double mealPrice() {
double breakfastPrice = 10.50;
return breakfastPrice;
}
}
final double mealPrice() { return 0; }
}
(Choose correct one from multiple below)
1. Compile with error
2. Compile without error
3. None of the above
4. None of the above
correct is :1
Explanations :WRONG! Compilation error! Cannot override the final method from Meal.
An enum type that contains constant-specific class bodies implicitily final:
------------------------------------------------------------------------------
Question No :12
What is the output of the bellow code ?
public enum Test {
BREAKFAST(7, 30){
public double final mealPrice() {
double breakfastPrice = 10.50;
return breakfastPrice;
}
}
, LUNCH(12, 15), DINNER(19, 45);
private int hh;
private int mm;
Test(int hh, int mm) {
assert (hh >= 0 && hh <= 23) : "Illegal hour.";
assert (mm >= 0 && mm <= 59) : "Illegal mins.";
this.hh = hh;
this.mm = mm;
}
public int getHour() {
return hh;
}
public int getMins() {
return mm;
}
public static void main(String args[]){
Test t = BREAKFAST;
System.out.println(t.getHour() +":"+t.getMins());
}
}
(Choose correct one from multiple below)
1. 7:30
2. Compile with error
3. Runtime Exceptions
4. None of the above
correct is :2
Explanations :An enum type that contains constant-specific class bodies cannot be declared final:
------------------------------------------------------------------------------
Question No :13
Which is the bellow statement is true about java.util.EnumSet ?
(Choose correct one from multiple below)
1. All of the elements in an enum set MUST come from a single enum type.
2. The null reference CANNOT be stored in an enum set.
3. all methods are static except for the clone() method.
4. All of the above
correct is :4
Explanations :java.util.EnumSet
Enums can be used in a special purpose Set implementation (EnumSet) which provides better
performance.
All of the elements in an enum set MUST come from a single enum type.
Enum sets are represented internally as bit vectors.
The EnumSet class defines new methods and inherits the ones in the Set/Collection interfaces.
NOTE, all methods are static except for the clone() method.
All methods return an EnumSet.
The null reference CANNOT be stored in an enum set.
------------------------------------------------------------------------------
Question No :14
What is the output for the bellow code ?
import java.util.EnumSet;
import static java.lang.System.out;
public class UsingEnumSet {
enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
public static void main(String[] args) {
EnumSet allDays = EnumSet.range(Day.MONDAY, Day.SUNDAY);
System.out.println("All days: " + allDays);
}
(Choose correct one from multiple below)
1. All days: [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
2. All days: [MONDAY, SUNDAY]
3. Compile with error
4. None of the above
correct is :1
Explanations :EnumSet.range(from, to) : Creates an enum set initially containing all of the
elements in the range defined by the two specified endpoints
------------------------------------------------------------------------------
Question No :15
Is the bellow statement is true ?
The null reference CANNOT be stored in an enum set.
(Choose correct one from multiple below)
1. true
2. false
3. Can't say
4. None of the above
correct is :1
Explanations :java.util.EnumSet
Enums can be used in a special purpose Set implementation (EnumSet) which provides better
performance.
All of the elements in an enum set MUST come from a single enum type.
Enum sets are represented internally as bit vectors.
The EnumSet class defines new methods and inherits the ones in the Set/Collection interfaces.
NOTE, all methods are static except for the clone() method.
All methods return an EnumSet.
The null reference CANNOT be stored in an enum set.
------------------------------------------------------------------------------
Question No :16
What is the output of bellow code ?
import java.util.EnumSet;
import static java.lang.System.out;
public class UsingEnumSet {
enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
public static void main(String[] args) {
EnumSet oddDays = EnumSet.of(Day.MONDAY, Day.WEDNESDAY,
Day.FRIDAY, Day.SUNDAY);
out.println("Odd days: " + oddDays);
EnumSet evenDays = EnumSet.complementOf(oddDays);
out.println("Even days: " + evenDays);
}
}
(Choose correct one from multiple below)
1. Compile with error
2. Odd days: [MONDAY, WEDNESDAY, FRIDAY, SUNDAY]
Even days: [TUESDAY, THURSDAY, SATURDAY]
3. Odd days: [MONDAY, WEDNESDAY, FRIDAY, SUNDAY]
Even days: [MONDAY, WEDNESDAY, FRIDAY, SUNDAY]
4. None of the above
correct is :2
Explanations :EnumSet.of() :Creates an enum set initially containing the specified element.
EnumSet.complementOf() :Creates an enum set with the same element type as the specified
enum set, initially containing all the elements of this type that are not contained in the specified
set.
------------------------------------------------------------------------------
Question No :17
What is true about java.util.EnumMap ?
(Choose correct one from multiple below)
1. The null reference as a key is NOT permitted.
2. All of the keys in an enum map MUST come from a single enum type.
3. Enum maps are maintained in the natural order of their keys
4. All of the above
correct is :4
Explanations :java.util.EnumMap
Enums can be used in a special purpose Map implementation (EnumMap) which provides better
performance.
Enum maps are represented internally as arrays.
All of the keys in an enum map MUST come from a single enum type.
Enum maps are maintained in the natural order of their keys (i.e. the order of the enum constant
declarations).
The EnumMap class re-implements most of the methods in the Map interface.
The null reference as a key is NOT permitted.
------------------------------------------------------------------------------
Question No :18
Is the bellow statement is true for java.util.EnumMap ?
The null reference as a key is NOT permitted.
(Choose correct one from multiple below)
1. true
2. false
3. Can't day
4. None of the above
correct is :1
Explanations :The null reference as a key is NOT permitted.
------------------------------------------------------------------------------
Question No :19
Is the bellow statement is true for java.util.EnumMap ?
"All of the keys in an enum map MUST come from a single enum type"
(Choose correct one from multiple below)
1. true
2. false
3. Can't say
4. None of the above
correct is :1
Explanations :java.util.EnumMap
Enums can be used in a special purpose Map implementation (EnumMap) which provides better
performance.
Enum maps are represented internally as arrays.
All of the keys in an enum map MUST come from a single enum type.
Enum maps are maintained in the natural order of their keys (i.e. the order of the enum constant
declarations).
The EnumMap class re-implements most of the methods in the Map interface.
The null reference as a key is NOT permitted.
------------------------------------------------------------------------------
Question No :20
What is the output for the bellow code ?
public class Test {
enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
public static void main(String[] args) {
int[] freqArray = { 12, 34, 56, 23, 5, 13, 78 };
// Create a Map of frequencies
Map ordinaryMap = new HashMap();
for (Day day : Day.values()) {
ordinaryMap.put(day, freqArray[day.ordinal()]);
}
// Create an EnumMap of frequencies
EnumMap frequencyEnumMap = new EnumMap(ordinaryMap);
// Change some frequencies
frequencyEnumMap.put(Day.MONDAY, 100);
frequencyEnumMap.put(Day.FRIDAY, 123);
System.out.println("Frequency EnumMap: " + frequencyEnumMap);
}
}
(Choose correct one from multiple below)
1. Frequency EnumMap: {MONDAY=100, TUESDAY=34, WEDNESDAY=56, THURSDAY=23,
FRIDAY=123, SATURDAY=13, SUNDAY=78}
2. Frequency EnumMap: {MONDAY=12, TUESDAY=34, WEDNESDAY=56, THURSDAY=23,
FRIDAY=5, SATURDAY=13, SUNDAY=78}
3. Compile with error
4. None of the above
correct is :1
Explanations :// Creates an empty enum map with the specified key type.
EnumMap(Class keyType)
// Creates an enum map with the same key type as the specified enum map, initially
// containing the same mappings (if any).
EnumMap(EnumMap m)
// Creates an enum map initialized from the specified map.
EnumMap(Map m)
------------------------------------------------------------------------------
Question No :21
What is the output for bellow code ?
public class Test {
enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
public static void main(String[] args) {
int[] freqArray = { 12, 34, 56, 23, 5, 13, 78 };
// Create a Map of frequencies
Map ordinaryMap = new HashMap();
for (Day day : Day.values()) {
ordinaryMap.put(day, freqArray[day.ordinal()]);
}
// Create an EnumMap of frequencies
EnumMap frequencyEnumMap = new EnumMap(ordinaryMap);
// Change some frequencies
frequencyEnumMap.put("abc", 100);
frequencyEnumMap.put("bcd", 123);
System.out.println("Frequency EnumMap: " + frequencyEnumMap);
}
}
(Choose correct one from multiple below)
1. Frequency EnumMap: {MONDAY=100, TUESDAY=34, WEDNESDAY=56, THURSDAY=23,
FRIDAY=123, SATURDAY=13, SUNDAY=78}
2. Frequency EnumMap: {abc=100,bcd=123,MONDAY=100, TUESDAY=34, WEDNESDAY=56,
THURSDAY=23, FRIDAY=123, SATURDAY=13, SUNDAY=78}
3. Compile with error
4. None of the above
correct is :3
Explanations :All of the keys in an enum map MUST come from a single enum type.
------------------------------------------------------------------------------
Question No :22
What is the output for the bellow code ?
public class Test {
enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
enum Month {
JAN, FEB
}
public static void main(String[] args) {
int[] freqArray = { 12, 34, 56, 23, 5, 13, 78 };
// Create a Map of frequencies
Map ordinaryMap = new HashMap();
for (Day day : Day.values()) {
ordinaryMap.put(day, freqArray[day.ordinal()]);
}
// Create an EnumMap of frequencies
EnumMap frequencyEnumMap = new EnumMap(ordinaryMap);
// Change some frequencies
frequencyEnumMap.put(Month.JAN, 100);
System.out.println("Frequency EnumMap: " + frequencyEnumMap);
}
}
(Choose correct one from multiple below)
1. Frequency EnumMap: {JAN=100,MONDAY=100, TUESDAY=34, WEDNESDAY=56,
THURSDAY=23, FRIDAY=123, SATURDAY=13, SUNDAY=78}
2. Compile with error
3. Runtime Exception
4. None of the above
correct is :2
Explanations :All of the keys in an enum map MUST come from a single enum type.
EnumMap is trying to add key from both the enums(Day and Month).
------------------------------------------------------------------------------
Question No :23
What is the output for the bellow code?
public class Test {
enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
enum Month {
JAN, FEB
}
public static void main(String[] args) {
int[] freqArray = { 12, 34, 56, 23, 5, 13, 78 };
// Create a Map of frequencies
Map ordinaryMap = new HashMap();
for (Day day : Day.values()) {
ordinaryMap.put(day, freqArray[day.ordinal()]);
}
// Create an EnumMap of frequencies
EnumMap frequencyEnumMap = new EnumMap(ordinaryMap);
// Change some frequencies
frequencyEnumMap.put(null, 100);
System.out.println("Frequency EnumMap: " + frequencyEnumMap);
}
}
(Choose correct one from multiple below)
1. Compile with error
2. NullPointerException
3. Successfully run
4. None of the above
correct is :2
Explanations :The null reference as a key is NOT permitted. so
Exception in thread "Main Thread" java.lang.NullPointerException:
at java.util.EnumMap.typeCheck(EnumMap.java:645)
at java.util.EnumMap.put(EnumMap.java:231)
------------------------------------------------------------------------------
Question No :24
What is the output for the bellow code ?
public class Test {
enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
public static void main(String[] args) {
EnumSet allDays = EnumSet.range(Day.MONDAY, Day.SUNDAY);
allDays.add(null);
System.out.println("All days: " + allDays);
}
}
(Choose correct one from multiple below)
1. All days: [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
2. All days: [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY,
SUNDAY,null]
3. java.lang.NullPointerException:
4. None of the above
correct is :3
Explanations :The null reference CANNOT be stored in an enum set.
Exception in thread "Main Thread" java.lang.NullPointerException:
at java.util.EnumSet.typeCheck(EnumSet.java:360)
at java.util.RegularEnumSet.add(RegularEnumSet.java:141)
at java.util.RegularEnumSet.add(RegularEnumSet.java:18)
------------------------------------------------------------------------------
Distribution of this pdf is illegal without permission of techfaq360.com

SCJP Mock Questions : Declarations, Initialization and Scoping

********************************************************************
original from www.techfaq360.com
SCJP Mock Questions : Declarations, Initialization and Scoping
********************************************************************
Question No :1
Which statement is true?
(Choose correct one from multiple below)
1. A class may be declared final, in which case it cannot have subclasses .
2. A class can't declared final
3. A class may be declared final, in which case it can have subclasses
4. None of the above
correct is :1
Explanations :A class may be declared final, in which case it cannot have subclasses
------------------------------------------------------------------------------
Question No :2
Which statement is true?
(Choose correct one from multiple below)
1. outer class can only declare public , abstract and final
2. outer class may be private
3. outer class can't be abstract
4. None of the above
correct is :1
Explanations :outer class can only declare public , abstract and final
------------------------------------------------------------------------------
Question No :3
Is the bellow statement is true?
"abstract class cannot be instantiated, but can be extended by subclasses"
(Choose correct one from multiple below)
1. true
2. false
3. None of the above
4. None of the above
correct is :1
Explanations :abstract class cannot be instantiated, but can be extended by subclasses.
------------------------------------------------------------------------------
Question No :4
What is the output ?
public interface TestInf {
int i =10;
}
public class Test {
public static void main(String... args) {
TestInf.i=12;
System.out.println(TestInf.i);
}
}
(Choose correct one from multiple below)
1. Compile with error
2. 10
3. 12
4. None of the above
correct is :1
Explanations :All the variables declared in interface is Implicitly static and final , so can't change
the value.
------------------------------------------------------------------------------
Question No :5
What is the output ?
public class Test {
public static void main(String... args) {
final int i;
System.out.println(i);
}
}
(Choose correct one from multiple below)
1. Compile with error
2. 0
3. Runtime Exception
4. None of the above
correct is :1
Explanations :final variables should be initialized.
------------------------------------------------------------------------------
Question No :6
What will be the result of compiling the following code:
public class Test {
public static void main(String... args) {
static int i;
System.out.println(i);
}
}
(Choose correct one from multiple below)
1. the code will compile and print 0
2. the code will compile an print null
3. Complile time error.
4. None of the above
correct is :3
Explanations :static variables should not be local.
------------------------------------------------------------------------------
Question No :7
public class A extends Integer{
public static void main(Sring[] args){
System.out.println("Hello");
}
}
What is the output?
(Choose correct one from multiple below)
1. Hello
2. Compile Error
3. Runtime
4. None of the above
correct is :2
Explanations :final class can't be extended. Integer is final class.
------------------------------------------------------------------------------
Question No :8
private class B {
public static void main(String[] args){
System.out.println("DD");
B b = new B();
}
}
What is the output ?
(Choose correct one from multiple below)
1. DD
2. Compile Error.
3. Runtime Exception
4. None of the above.
correct is :2
Explanations :Only public, abstract and final is permitted for class modifier.
------------------------------------------------------------------------------
Question No :9
public class Point {
int x = 1, y = 1;
abstract void alert();
}
Is the code compile without error ?
(Choose correct one from multiple below)
1. compile without error
2. compile with error , because class should be abstract.
3. Can't say
4. None of the above.
correct is :2
Explanations :If there is any abstract method in a class then the class should be abstract.
------------------------------------------------------------------------------
Question No :10
abstract class Point {
int x = 1, y = 1;
abstract void alert();
}
public class A{
public static void main(String[] args){
Point p = new Point();
}
}
What is the output ?
(Choose correct one from multiple below)
1. compile without error
2. compile with error.
3. Can't say
4. None of the above.
correct is :2
Explanations :abstract class can't be instantiated.
------------------------------------------------------------------------------
Question No :11
Which bellow statement is true?
(Choose correct one from multiple below)
1. A subclass of an abstract class that is not itself abstract may be instantiated.
2. abstract class can't be instantiated.
3. Both are true
4. None of the above
correct is :3
Explanations :No explanation available
------------------------------------------------------------------------------
Question No :12
What is the correct ordering for the import, class and package declarations when found in a Java
class?
(Choose correct one from multiple below)
1. package, import, class
2. class, import, package
3. import, package, class
4. package, class, import
correct is :1
Explanations :Example :
package com;
import java.io.IOException;
public class Test {
}
------------------------------------------------------------------------------
Question No :13
What will be the result of compiling the following code:
public class Test {
public static void main (String args []) {
int age;
age = age + 1;
System.out.println("The age is " + age);
}
}
(Choose correct one from multiple below)
1. the code will compile an print 1.
2. the code will compile an print 0.
3. Complile time error.
4. None of the above
correct is :3
Explanations :local variable should be initialized.
------------------------------------------------------------------------------
Question No :14
What will be the result of compiling the following code:
public class Test {
static int age;
public static void main (String args []) {
age = age + 1;
System.out.println("The age is " + age);
}
}
(Choose correct one from multiple below)
1. The code does not compile.
2. The code compiles cleanly and print 1.
3. The code compiles cleanly and print 0.
4. The code throws an Exception at Runtime.
correct is :2
Explanations :static variables are initiatized automatically. default initialization value for int is 0 and
boolean is false.
------------------------------------------------------------------------------
Question No :15
Which of the following can be used to define a constructor for this class, given the following code:
public class Test {
...
}
(Choose correct one from multiple below)
1. public void Test() {...}
2. public Test() {...}
3. public static Test() {...}
4. public static void Test() {...}
correct is :1
Explanations :Constructor should not have any return type and should not be static.
------------------------------------------------------------------------------
Question No :16
Is this legal
public class Test {
static { int a = 5; }
public static void main(String[] args){
System.out.println(a);
}
}
(Choose correct one from multiple below)
1. Yes
2. No
3. Can't Say
4. None
correct is :2
Explanations :A variable declared in a static initialiser is not accessible outside its enclosing block.
------------------------------------------------------------------------------
Question No :17
class c2
{
{
System.out.println("initializer");
}
public static void main(String a[])
{
System.out.println("main");
c2 ob1=new c2();
}
}
(Choose correct one from multiple below)
1. prints main and initializer
2. prints initializer and main
3. compile time error
4. None of the above
correct is :1
Explanations :statement block executes on creation of object of the class.
------------------------------------------------------------------------------
Question No :18
public class A {
static{System.out.println("static");}
{ System.out.println("block");}
public A(){
System.out.println("A");
}
public static void main(String[] args){
A a = new A();
}
What will be output ?
(Choose correct one from multiple below)
1. A block static
2. static block A
3. static A
4. A
correct is :2
Explanations :First execute static block, then block then constructor.
------------------------------------------------------------------------------
Question No :19
class Bird {
{ System.out.print("b1 "); }
public Bird() { System.out.print("b2 "); }
}
class Raptor extends Bird {
static { System.out.print("r1 "); }
public Raptor() { System.out.print("r2 "); }
{ System.out.print("r3 "); }
static { System.out.print("r4 "); }
}
class Hawk extends Raptor {
public static void main(String[] args) {
System.out.print("pre ");
new Hawk();
System.out.println("hawk ");
}
}
What is the output?
(Choose correct one from multiple below)
1. r1 r4 pre b1 b2 r3 r2 hawk
2. r1 r4 pre b1 b2 hawk
3. r1 r4 pre b1 b2 hawk r3 r2
4. None of the above
correct is :1
Explanations :All static blocks execute first : sequesnce super class first
Blocks execute : sequesnce super class first
------------------------------------------------------------------------------
Question No :20
class Bird {
int i;
boolean b;
float f;
public Bird() {
System.out.println(i);
System.out.println(b);
System.out.println(f);
}
}
What is the output?
(Choose correct one from multiple below)
1. 0 false 0.0
2. 0 true 0.0
3. Not Compile
4. None of the above
correct is :1
Explanations :Jvm initialize default values;
Static vaiables also;
------------------------------------------------------------------------------
Question No :21
What is the result that will be printed out ?
void aMethod()
{
float f = (1 / 4) * 10;
int i = Math.round(f);
System.out.println(i);
(Choose correct one from multiple below)
1. 3
2. 0
3. 2
4. 2.5
correct is :2
Explanations :The result of 1/4 will be zero because integer
divion is carried out on the operands.
If you need to obtain a fractional value
you need to use either a float or double literal
as in 1F / 4F.
------------------------------------------------------------------------------
Question No :22
int a = 7;
int b = 4;
a = b;
a = a + 1;
System.out.println(a);
what will be the output ?
(Choose correct one from multiple below)
1. 8
2. 5
3. 7
4. 4
correct is :2
Explanations :No explanation available
------------------------------------------------------------------------------
Question No :23
What is the output?
System.out.println("The answer is: "+18+3);
(Choose correct one from multiple below)
1. 21
2. 183
3. Comiple Error
4. None
correct is :2
Explanations :No explanation available
------------------------------------------------------------------------------
Question No :24
class C {
public static void main(String[] args) {
int i1=1;
switch(i1){
case 1:
System.out.println("one");
case 2:
System.out.println("two");
case 3:
System.out.println("three");
}}}
(Choose correct one from multiple below)
1. prints one two three
2. prints one
3. compile time error
4. Runtime exceptionf
correct is :1
Explanations :There is no break statement in case 1 so it causes the below case statements to
execute regardless of their values
------------------------------------------------------------------------------
Question No :25
class C1
{
static class C2
{
static int i1;
}
public static void main(String a[])
{
System.out.println(C1.C2.i1);
}
}
(Choose correct one from multiple below)
1. prints 0
2. Compile time error
3. Runtime exception
4. None of the above
correct is :1
Explanations :static members can be accessed without instantiating the particular class
------------------------------------------------------------------------------
Question No :26
class C {
public static void main(String[] args) {
int[]a1[]=new int[3][3]; //3
int a2[4]={3,4,5,6}; //4
int a2[5]; //5
}}
(Choose correct one from multiple below)
1. compiletime error at lines 3,4,5
2. compiltime error at line 4,5
3. compiletime error at line 3
4. Runtime Exception
correct is :2
Explanations :no value shoud be specified in the rightsidebrackets when constructing an array
------------------------------------------------------------------------------
Question No :27
class C{
int i;
public static void main (String[] args) {
int i; //1
private int a = 1; //2
protected int b = 1; //3
public int c = 1; //4
System.out.println(a+b+c); //5
}}
(Choose correct one from multiple below)
1. compiletime error at lines 1,2,3,4,5
2. compiletime error at lines 2,3,4,5
3. compiletime error at lines 2,3,4
4. prints 3
correct is :2
Explanations :The access modifiers public, protected and private, can not be applied to variables
declared inside methods.
------------------------------------------------------------------------------
Distribution of this pdf is illegal without permission of techfaq360.com