You are on page 1of 7

Multiple Choice Questions 1) Consider the following program: import myLibrary.

*; public class ShowSomeClass { // code for the class... } What is the name of the java file containing this program? A. myLibrary.java B. C. D. E. ShowSomeClass.java ShowSomeClass ShowSomeClass.class Any file name with the java suffix will do

2) Which of the following is TRUE? A. In java, an instance field declared public generates a compilation error. B. C. int is the name of a class available in the package java.lang Instance variable names may only contain letters and digits.

D. A class has always a constructor (possibly automatically supplied by the java compiler). E. The more comments in a program, the faster the program runs.

3) Consider the following code snippet String river = new String(Columbia); System.out.println(river.length()); What is printed? A. 6 B. 7 C. 8 D. Columbia

E. river 4) A constructor A. must have the same name as the class it is declared within. B. C. D. E. is used to create objects. may be declared private A and B A, B and C

5) Which of the following may be part of a class definition? A. instance variables B. C. D. E. instance methods constructors all of the above none of the above

6.) What is different between a Java applet and a Java application? A. An application can in general be trusted whereas an applet can't. B. C. D. E. An applet must be executed in a browser environment. An applet is not able to access the files of the computer it runs on (A), (B) and (C). None of the above

7) Consider public class MyClass{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write? A. MyClass mc = new MyClass();

B. C. D. E.

MyClass mc = MyClass(); MyClass mc = MyClass; MyClass mc = new MyClass; It can't be done. The constructor of MyClass should be defined as

public void MyClass(){/*code*/} 8) What is byte code in the context of Java? A. The type of code generated by a Java compiler B. C. D. E. The type of code generated by a Java Virtual Machine It is another name for a Java source file It is the code written within the instance methods of a class. It is another name for comments written within a program.

9) What is garbage collection in the context of Java? A. The operating system periodically deletes all of the java files available on the system. B. C. Any package imported in a program and not used is automatically deleted. When all references to an object are gone, the memory used by the object is

automatically reclaimed. D. The JVM checks the output of any Java program and deletes anything that

doesn't make sense. E. Janitors working for Sun MicroSystems are required to throw away any

Microsoft documentation found in the employees' offices. 10) You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure? A. depth must be an int B. dive must be a method.

C. D. E.

dive must be the name of an instance field. submarine must be the name of a class submarine must be a method.

10. Pick the incorrect statement: A) A class can implement more than one interface B) A class can extend more than one classes C) An interface can extend more than one interfaces D) An interface cannot extend a class 11. Which statement is true for the class java.util.HashSet? (A.) The elements in the collection are ordered. (B.) (C.) (D.) The collection is guaranteed to be immutable. The elements in the collection are guaranteed to be unique. The elements in the collection are accessed using a unique key.

12. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability? * (A.) java.util.Map (B.) (C.) (D.) java.util.Set java.util.List java.util.Collection

13) The method used to start a thread execution: * (A.) init() (B.) (C.) (D.) start() run() resume()

14) Choose the right statement: * (A.) Runnable interface is defined in the java.lang package

(B.) (C.) (D.)

Runnable has 2 methods declared in it Runnable interface cannot be used to create threads All are correct

15) A class implements an interface but does not override all the methods of that interface, then ______ (A) It should be declared as abstract class ( B) It should be declared as final class (C)It will compile successfully (D) none of these 16) To remove duplicate rows from the results of an SQL SELECT statement, the ________ qualifier specified must be included. A.)ONLY B.)UNIQUE C.)DISTINCT D.)SINGLE 17) Which of the following is the correct order of keywords for SQL SELECT statements? A. B. C. D. SELECT, FROM, WHERE FROM, WHERE, SELECT WHERE, FROM,SELECT SELECT,WHERE,FROM

18) Evaluate this SQL statement: SELECT employee_id, e.department_id, department_name, salary FROM employees e, departments d WHERE e.department_id = d.department_id; 19) Which SQL statement is equivalent to the above SQL statement? A) SELECT employee_id, department_id, department_name, salary FROM employees WHERE department_id IN (SELECT department_id FROM departments); B) SELECT employee_id, department_id, department_name, salary FROM employees

NATURAL JOIN departments; C) SELECT employee_id, d.department_id, department_name, salary FROM employees e JOIN departments d ON e.department_id = d.department_id; D) SELECT employee_id, department_id, department_name, salary FROM employees JOIN departments USING (e.department_id, d.department_id); 20) Linked lists are suitable for which of the following problems ? A)Insertion sort B)Binary search C)Radix sort D)Polynomial manipulation 21) Which statement is true? A.) A try statement must have at least one corresponding catch block. B.) Multiple catch statements can catch the same class of exception more than once. C.) An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method. D.)Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute. 22) which statement, inserted at line 10, creates an instance of Bar? A. Foo.Bar b = new Foo.Bar(); B. Foo.Bar b = f.new Bar(); C. Bar b = new f.Bar(); D. Bar b = f.new Bar(); 23.) Write a java program to reverse a string. 24.) write a java program to read a copy one text files to another . 25.)write a program to implement STACK.

You might also like