Wednesday, August 4, 2010

Identifiers, Arrays and Enums:

Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 1, Question 7

This program fails compilation:

line 4: variable name cannot begin with #

line 5: array declaration cannot specify size until it includes instantiation (points to memory in heap). To correct this line, re-write as long [][] x = new long [some number][5];

line 10: (courtesy of enums cannot be declared in a method. This is because an enum can be considered as a class (with a private constructor). A class inside a method would be a Method Local Inner Class. Also, the modifier of an enum can be public, which is not allowed for a Method Local Inner Class. Furthermore the enum was born to replace the constants (public static final) and these were static class members (which you wouldn't define in a method either)

No comments:

Post a Comment