Posts

Showing posts with the label SCJP Mock Questions

SCJP 5 Mock Questions on Declarations, Initialization and Scoping

Given: 5. enum Towns1{NY, LA, SF} 6. 7. public class DeclareEnum { 8. 9. enum Towns2{NY, LA, SF}; 10. 11. public static void main(String [] args) { 12. enum Towns3{NY, LA, SF}; 13. } 14. } What is the result? A The code compiles. B Compilation fails due to an error on line 5. C Compilation fails due to an error on line 9. D Compilation fails due to an error on line 12. E Compilation fails due to errors on lines 5 and 12. F Compilation fails due to errors on lines 9 and 12. Reference Close JLS 3.0, 8.9 Option D is correct. An enum may NOT be declared in a method. --------------------------------- Location: ... > Section 1: Declarations, Initialization and Scoping > Objective 1.1 > Question 2 Your answer is correct. Given three different source files: 1. package com.sun2; 2. public enum Seasons {SUMMER, FALL, WINTER, SPRING } And: 1. import com.sun2.Seasons; 2. class Enum3a { 3. Seasons s = Seasons.FALL...

SCJP 1.4 Mock Questions on Basic JAVA

Question 1 class GRC7 {public void main(String[] args) {}} // 1 class GRC8 {public void main(String []args) {}} // 2 class GRC9 {public void main(String args[]) {}} // 3 What is the result of attempting to compile and run the above programs? a. Compile-time error at line 1. b. Compile-time error at line 2. c. Compile-time error at line 3. d. An attempt to run GRC7 from the command line fails. e. An attempt to run GRC8 from the command line fails. f. An attempt to run GRC9 from the command line fails. Question 2 class MCZ29 { public static void main (String[] args) { char a = '\a'; // 1 char b = '\b'; // 2 char c = '\f'; // 3 char d = '\n'; // 4 char e = '\r'; // 5 }} A compile-time error is generated at which line? a. 1 b. 2 c. 3 d. 4 e. 5 f. None of the above Question 3 class MCZ30 { public static void main (String[] args) { char a = '\t'; // 1 char b = '\\'; // 2 char c = '\?'; // 3 char d = '\"'; // 4 char ...