|
Directions to Solve
In questions below, each passage consist of six sentences. The first and sixth sentence are given in the begining. The middle four sentences in each have been removed and jumbled up. These are labelled as P, Q, R and S. Find out the proper order for the four sentences.
ANS:C - QPRS
No answer description is available.
|
A Error: Doesn't print anything
B Error: Not allowed assignment
ANS:A - Error: Not allowed assignment
The function void f() is not visible to the compiler while going through main() function. So we have to declare this prototype void f(); before to main() function. This kind of error will not occur in modern compilers.
|
A Compilation will fail at line 3.
B Compilation will fail at line 5.
C Compilation will succeed.
D Compilation will fail at line 15.
ANS:A - Compilation will succeed.
Option B is correct. The compiler complains with the error "modifier private not allowed here". The class is created private and is being used by another class on line 19.
|
B NullPointerException at runtime ANS:A - 0
In the above code the array reference variable x has been declared but it has not been instantiated i.e. the new statement is missing, for example:
private static int[]x = new int[5];
private static int[x] declares a static i.e. class level array.
the 'new' keyword is the word that actually creates said array.
int[5] in association with the new sets the size of the array. so since the above code contains no new or size decalarations when you try and access x[0] you are trying to access a member of an array that has been declared but not intialized hence you get a NullPointerException at runtime.
|
A Prints: false, false, true
B Prints: false, true, false
C Prints: false, false, false
D Prints: false, true, true
ANS:A - Prints: false, false, false
The iterator() method returns an iterator over the elements in the list in proper sequence, it doesn't return a List or a ListIterator object.
A ListIterator can be obtained by invoking the listIterator method.
|
ANS:A - f[0] = 0
The choices are between Option A and B, what this question is really testing is your knowledge of default values of an initialized array. This is an array type float i.e. it is a type that uses decimal point numbers therefore its initial value will be 0.0 and not 0
|
A Prints: false,false,true
B Prints: true,false,false
C Prints: false,true,false
D Prints: false,false,false
ANS:A - Prints: false,false,false
The Vector.elements method returns an Enumeration over the elements of the vector. Vector implements the List interface and extends AbstractList so it is also possible to get an Iterator over a Vector by invoking the iterator or listIterator method.
|
ANS:A - one two three four
TreeSet assures no duplicate entries; also, when it is accessed it will return elements in natural order, which typically means alphabetical.
|
A Compile Error at line 2
B Compile Error at line 5
ANS:A - 42
This code is an example of an anonymous inner class. They can be declared to extend another class or implement a single interface. Since they have no name you can not use the 'new' keyword on them.
In this case the annoynous class is extending the Object class. Within the {} you place the methods you want for that class. After this class has been declared its methods can be used by that object in the usual way e.g. objectname.annoymousClassMethod()
|
A class Test2 will not compile. B The Test1 hashCode() method is more efficient than the Test2 hashCode() method.
C The Test1 hashCode() method is more efficient than the Test2 hashCode() method. D
The Test1 hashCode() method is more efficient than the Test2 hashCode() method.
ANS:A -
The Test1 hashCode() method is more efficient than the Test2 hashCode() method.
The so-called 'hashing algorithm' implemented by class Test1 will always return the same value, 42, which is legal but which will place all of the hash table entries into a single bucket, the most inefficient setup possible.
Option A and D are incorrect because these classes are legal.
Option B is incorrect based on the logic described above. |