Java Programming Language Quiz - 4
Java Programming Language Quiz - 4
Questions
Question 1 Multiple Choice (Multiple Answers)
What is the output of following piece of code ?
int x = 2;
switch (x) {
case 1:System.out.println("1?);
case 2:
case 3:System.out.println("3?);
case 4:
case 5:System.out.println("5?);
}
- No output
- 3 and 5
- 1, 3 and 5
- 3
Question 2 Multiple Choice (Single Answer)
A method is defined in a class as : void processUser(int i) { } If this method is overriden in a sub class,_
- the new method should return int
- the new method can return any type of values
- the argument list of new method should exactly match that of overriden method
- the return type of new method should exactly match that of overriden method
Question 3 Multiple Choice (Multiple Answers)
A Vector is declared as follows. What happens if the code tried to add 6 th element to this Vector new vector(5,10)
- The element will be successfully added
- ArrayIndexOutOfBounds Exception
- The Vector allocates space to accommodate up to 15 elements
- none of these
Question 4 Multiple Choice (Single Answer)
A class can be converted to a thread by implementing the interface ___.
- Thread
- Runnable
- Both of these
- none of these
Question 5 Multiple Choice (Single Answer)
Given:
TreeSet map = new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four"};
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() ) {
System.out.print( it.next() + " " );
}
- Compilation fails
- one two three four
- four three two one
- four one three two
- one two three four one
- one four three two one
Question 6 Multiple Choice (Single Answer)
Which is true about a method-local inner class?
- It must be marked final
- It can be marked abstract
- It can be marked public
- It can be marked static
Question 7 Multiple Choice (Single Answer)
Which is true about an anonymous inner class?
- It can extend exactly one class and implement exactly one interface
- It can extend exactly one class and can implement multiple interfaces
- It can extend exactly one class or implement exactly one interface
- It can implement multiple interfaces regardless of whether it also extends a class
- It can implement multiple interfaces if it does not extend a class
Question 8 Multiple Choice (Single Answer)
Which is true?
- The java command can access classes from more than one package, from a single JAR file.
- JAR files can be used with the java command but not with the javac command.
- In order for JAR files to be used by java, they MUST be placed in the /jre/lib/ext sub-directory within the J2SE directory tree.
- When a part of a directory tree that includes subdirectories with files is put into a JAR file, all of the files are saved in the JAR file, but the subdirectory structure is lost.
Question 9 Multiple Choice (Single Answer)
Which of the following statement is true?
- X extends Y is correct if and only if X is a class and Y is an interface
- X extends Y is correct if and only if X is an interface and Y is a class
- X extends Y is correct if X and Y are either both classes or both interfaces
- X extends Y is correct for all combinations of X and Y being classes and/or interfaces.