(Quiz) SCJP (Sun Certified Java Program) Language Fundamentals
QUIZ: SCJP (Sun Certified Java Program) Language Fundamentals
Questions 1 Which of the following lines are valid declarations?
(a) char a = ‘\u0061’;
(b) char \u0061 = ‘a’;
(c) ch\u0061r a = ‘a’;
(d) char a = (char) 65;
Answers: 1 (a), (b), (c), (d)
All are valid declarations. The \uxxxx notation can be used anywhere in the source to represent Unicode characters, and also casted integer to a char primitive type.
Questions 2 Is an empty file a valid source file?
(a) True.
(b) False.
Answers: 2 (a)
Although nonsensical, an empty file ia a valid source file. A source file can contain an optional package declaration, any number of import statements and any number of class and interface definitions.
Questions 3 Which of these are valid declaration of the main() method?
(a) static void main(String args[]) {/* … */}
(b) public static int main(String args[]) {/* … */}
(c) public static void main(String args) {/* … */}
(d) final static public void main(String[] arguments) {/* … */}
(e) public int main(String args[], int argc) {/* … */}
(f) public void main(String args[]) {/* … */}
Answers: 3 (d)
A valid declaration of the main() method must be public and static, have void as return type and take a single array of String objects as arguments. The order of the static and public keywords is irrelevant. Also, declaring the method final does not affect the method’s potential to be used as a main()
method
Questions 4 Which one of the following are not valid character contants?
Select any two.
(a) char c = '\u00001' ;
(b) char c = '\101';
(c) char c = 65;
(d) char c = '\1001' ;
Answers: 4 (a), (d)
You cannot use five digits after \u."char c = 65" is valid because it will take it as ascii value. '\101' is representing a octal value which is equivalent to 65 which is valid but '\1001' is not valid as its decimal value is 513 and you can give only those values which represent 0 to 255 in decimal.
- guru's blog
- Login to post comments
