Java Programming Language Quiz - 4

Java Programming Language Quiz - 4

9 Questions Published

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?);
 }
  1. No output
  2. 3 and 5
  3. 1, 3 and 5
  4. 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,_

  1. the new method should return int
  2. the new method can return any type of values
  3. the argument list of new method should exactly match that of overriden method
  4. 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)

  1. The element will be successfully added
  2. ArrayIndexOutOfBounds Exception
  3. The Vector allocates space to accommodate up to 15 elements
  4. none of these
Question 4 Multiple Choice (Single Answer)

A class can be converted to a thread by implementing the interface ___.

  1. Thread
  2. Runnable
  3. Both of these
  4. 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() + " " );
 }
  1. Compilation fails
  2. one two three four
  3. four three two one
  4. four one three two
  5. one two three four one
  6. one four three two one
Question 6 Multiple Choice (Single Answer)

Which is true about a method-local inner class?

  1. It must be marked final
  2. It can be marked abstract
  3. It can be marked public
  4. It can be marked static
Question 7 Multiple Choice (Single Answer)

Which is true about an anonymous inner class?

  1. It can extend exactly one class and implement exactly one interface
  2. It can extend exactly one class and can implement multiple interfaces
  3. It can extend exactly one class or implement exactly one interface
  4. It can implement multiple interfaces regardless of whether it also extends a class
  5. It can implement multiple interfaces if it does not extend a class
Question 8 Multiple Choice (Single Answer)

Which is true?

  1. The java command can access classes from more than one package, from a single JAR file.
  2. JAR files can be used with the java command but not with the javac command.
  3. 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.
  4. 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?

  1. X extends Y is correct if and only if X is a class and Y is an interface
  2. X extends Y is correct if and only if X is an interface and Y is a class
  3. X extends Y is correct if X and Y are either both classes or both interfaces
  4. X extends Y is correct for all combinations of X and Y being classes and/or interfaces.