Here we presenting some tricky question for java readers :
- What gets displayed on the screen when the following program is compiled and run.
Select the one correct answer.
protected class example {
public static void main(String args[]) {
String test = "abc";
test = test + test;
System.out.println(test);
}
}
(A). The class does not compile because the top level class cannot be protected.
(B). The program prints "abc"
(C). The program prints "abcabc"
(D). The program does not compile because statement "test = test + test" is illegal. - Several questions about static:
(A). Can a static variable be declared within a method?
(B). Can a static method contain an inner class?
(C). Can a static method contain an static inner class? - TreeMap class is used to implement which collection interface.
Select the one correct answer.
(A). Set
(B). SortedSet
(C). List
(D). Tree
(E). SortedMap - Which of the following are legal declaration and definition of a method.
Select all correct answers.
(A). void method() {};
(B). void method(void) {};
(C). method() {};
(D). method(void) {};
(E). void method {}; - abstract class C1{
public void m1(){ //1
}}
abstract class C2{
public void m2(){ //2
}}
(A). compile time error at line1
(B). compile time error at line2
(C). The code compiles fine
(D). None of the above
~ Answers ~
Ans. 1. (A)
Ans. 2.
(A). No, not in Java, but yes in C++
(B). Yes
(C). No
The simplest way to have your doubts clarified is to write a short program, then compile it to see the result.
CODE, Code, code, ... please!
Ans. 3. (E)
Ans. 4. (A)
Ans. 5. (C) // since the class C2 is abstract it can contain abstract methods
No comments:
Post a Comment