Placement papers on Java - Set 2
1. How does the set collection deal with duplicate elements?
An exception is thrown if you attempt to add an element with a duplicate value
The add method returns false if you attempt to add an element with a duplicate value
A set may contain elements that return duplicate values from a call to the equals method
Duplicate values will cause an error at compile time
View Answer / Hide AnswerANSWER: The add method returns false if you attempt to add an element with a duplicate value
2. What can cause a thread to stop executing?
The program exits via a call to System.exit(0);
Another thread is given a higher priority
A call to the thread's stop method
All of the above
View Answer / Hide Answer3. For a class defined inside a method, what rule governs access to the variables of the enclosing method?
The class can access any variable
The class can only access static variables
The class can only access transient variables
The class can only access final variables
View Answer / Hide AnswerANSWER: The class can only access final variables
4. Under what circumstances might you use the yield method of the Thread class
To call from the currently running thread to allow another thread of the same or higher priority to run
To call on a waiting thread to allow it to run
To allow a thread of higher priority to run
To call from the currently running thread with a parameter designating which thread should be allowed to run
View Answer / Hide AnswerANSWER: To call from the currently running thread to allow another thread of the same or higher priority to run
5. Which of the following is the correct syntax for suggesting that the JVM performs garbage collection
System.free();
System.setGarbageCollection();
) System.out.gc();
System.gc();
View Answer / Hide Answer6. Which of the following will compile correctly
short myshort = 99S;
String name = 'Excellent tutorial Mr Green';
char c = 17c;
int z = 015;
View Answer / Hide Answer7. Which of the following are not Java key words
double
switch
then
instanceof
View Answer / Hide Answer8. Which of the following statements are true?
At the root of the collection hierarchy is a class called Collection
The collection interface contains a method called enumerator
The interator method returns an instance of the Vector class
The Set interface is designed for unique elements
View Answer / Hide AnswerANSWER: The Set interface is designed for unique elements
9. Which of the following statements are correct?
If multiple listeners are added to a component only events for the last listener added will be processed
If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
Adding multiple listeners to a comnponent will cause a compile time error
You can not remove or add listeners to a component.
View Answer / Hide AnswerANSWER: If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
10. What will be output by the following line of code? System.out.println(010|4);
14
0
6
12
View Answer / Hide Answer