"Learning is weightless, a treasure you can always carry easily." -Chinese Proverb
Originally posted by sunil choudhary:
Friends I recently gave the first sample test of Javaprepare
I am having a few doubts .... I have also mentioned my thinking on why I think a particular answer to be correct.
Which of the following is correct ? Select all correct answers.
A The native keyword indicates that the method is implemented in another language like C/C++.
B The only statements that can appear before an import statement in a Java file are comments.
C The method definitions inside interfaces are public and abstract. They cannot be private or protected.
D A class constructor may have public or protected keyword before them, nothing else.
The answer given is AB C
I say why B is correct package name comes even before the import statement.
When I am compiling the following code it gives Arithmatic Exception not found ???I wonder why ..... Hoewver teh answer it is giving is A D E
2 what will be the ouptut of following code
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithemticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
a 0
b 1
c 2
d 3
e 4
Which of the following are legal array declarations. Select all correct answers.
a int i[5][];
b int i[][];
c int []i[];
d int i[5][5];
e int[][] a;
ANS:
BC And E
I thought that all of these ways are true.
if tehre is an argumentr like in Arrrays the no of elements must be defined then I will aks why E is correct.
4)
If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class.
Select all correct answers.
a void method() { }
b int method() { return 0;}
c void method(int i) { }
d private void method() { }
the correct ans are A and c
My presumtion was that D should also be correct as the messsage body is void and it also declares the method to be void.Addition of Private just means that it can be accessed in its own package. or its subclasses.
Q5) Name the collection interface used to represent collections that maintain unique elements.
My Answer was Maps however javaprepare gives answer as Set
I saw in KM book and It seems that both allow only unique elemtns.
if both the answers are corre