You are on page 1of 15

1.

2.

3.

4.

5.

6. class

Which of the following is Java keyword? A) external B) implement C) throw D) Integer What gets printed when the following program is compiled and run? class test { public static void main (String args[]) { int i; do { i++; } while(i < 0); System.out.println(i); } } A) The program does not compile, as i is not initialized. B) The program compiles but does not run. C) The program compiles and runs but does not print anything. D) The program prints 0. The last statement in a finalize method should always be A) super (finalize) B) super.finalize( ) C) finalize(methodname) D) None of the above What gets printed when the following program is compiled and run? public class incr { public static void main (String args[]) { int i , j; i = j = 3; int n = 2 * ++i; int m = 2 * j++; System.out.println(i + " " + j + " " + n + " " + m); }} A) 4 4 8 6 B) 4 4 8 8 C) 4 4 6 6 D) 4 3 8 6 What is byte code in the context of Java? A) The type of code generated by a Java compiler B) The type of code generated by a Java Virtual Machine C) It is another name for a Java source file D) It is the code written within the instance methods of a class Which of the following keyword should be used to make a variable defined in a

accessible only to methods defined in the classes in same package. A) By using the keyword package before the variable. B) By using the keyword private before the variable. C) By using the keyword protected before the variable. D) The variable should not be preceded by any of the above-mentioned keywords. 7. Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class? A) The method converts an integer to a String.

8.

9.

10. class.

B) The method is used to convert String to an integer, assuming that the String represents an integer. C) The method is used to convert String to Integer class, assuming that the String represents an integer. D) The method converts the Integer object to a String. What is the default priority of a newly created thread? A) MIN_PRIORITY (which is defined as 1 in the Thread class.) B) NORM_PRIORITY (which is defined as 5 in the Thread class.) C) MAX_PRIORITY (which is defined as 10 in the Thread class.) D) A thread inherits the priority of its parent thread. Which one does not have a valueOf(String) method A) Integer B) Boolean C) Long D) Short Which of the following method is used to initialize the instance variable of a

A) Class B) Public C) Constructor D) Destructor 11. Examine the following code: public class LocalTest { public static void main(String args[]) { int i; System.out.println(int i = + i); i=20; } } If you try to compile and run this class, what will happen? A) It will compile, but will produce an interpreter error when executed. B) It will compile and output 0 to the screen. C) It will not compile and will give a compile error. D) None of the above. 12. Which looping construct are you guaranteed to enter? A) while B) do-while C) for D) none of the above 1.3 Which class is base class for all Exception? A) String B) Error C) Throwable D) RuntimeException 1.4 What will be the output of this code fragment? StringBuffer b=new StringBuffer(abcdefg); b.delete(3,6); b.append(hij); System.out.println(b.toString()); A) abcghij B) abcdefghij C) abfghij D) abchij

1.5 Which of the following classes directly implement the Set interface? A) Vector B) LinkedList C) HashSet D) HashTable 1.6 What value is returned from calling Math.sqrt(0.0)? A) 0.0 B) NaN C) ArithmeticException is thrown D) A compiler error is generated by calling Math.sqrt(0.0) 1.7 Which class is used for character stream in java.io? A) FileOutputStream B) ByteArrayOutputStream C) FileWriter D) PrintStream 1.8 A top level class may have only the following access modifier. A) package B) friendly C) private D) public 1.9 Which of the following must match exactly for overloaded methods to compile correctly? A) The parameter list B) The return type C) The method name D) None of the above 1.10What will be printed when the following program is compiled and run? class test { public static void main(String args[]) { int i, j, k, l=0; k = l++; j = ++k; i = j++; System.out.println(i); } } A) 0 B) 1 C) 2 D) 3 1.1 What will be the output of the following program? public class example { int i[] = {0}; public static void main(String args[]) { int i[] = {1}; change_i(i); System.out.println(i[0]); } public static void change_i(int i[]) { int j[] = {2}; i = j; } } A) The program does not compile. B) The program prints 0.

C) The program prints 1. D) The program prints 2. 1.2 Which of the following is an invalid declaration for the main method in java program? A) public static void main(String args[ ]) B) public static void main(String [ ]args) C) final static public void main (String args[ ]) D) public static int main(String args[ ]) A10.2-R3 Page 1 of 6 January, 2008 1.3 What gets printed on the standard output when the class below is compiled and executed? public class ShortCket { public static void main(String args[]) { int i = 0; boolean t = true, f = false, b; b = (t && ((i++) == 0)); b = (f && ((i+ = 2) > 0)); System.out.println(i); } } A) 0 B) 1 C) 2 D) 3 1.4 Which of the following statement is correct? A) For positive numbers, results of operators >> and >>> are same. B) Java provides two operators to do left shift <<< and <<. C) >> is the zero fill right shift operator. D) >>> is the signed right shift operator. 1.5 The new operator A) returns a pointer to a variable B) creates a variable called new C) obtains memory for a new variable D) tells how much memory is available 1.6 What will be the output of the following program? public class test { public static void main(String args[]) { byte x = 3; x = (byte) ~ x; System.out.println(x); } } A) 3 B) -4 C) 1 D) 0 1.7 A top level class may have which one of the following access modifiers: A) package B) private C) protected D) public 1.8 TreeMap class is used to implement which one of the following collection interfaces: A) Set B) SortedSet

C) SortedMap D) List 1.9 To get the object that generates the event which of the following method is used that is defined in EventObject class? A) getEvent() B) getObject() C) getID() D) getSource() 1.10 What would happen when the following is compiled and executed? public class Compare { public static void main(String args[]) { int x = 10, y; if(x < 10) y = 1; if(x >= 10) y = 2; System.out.println(y is +y); } } A) The program does not compile and complains about y not being initialized. B) The program compiles and prints y is 0 when executed. C) The program compiles and prints y is 1 when executed. D) The program compiles and prints y is 2 when executed. 1.1 A colored image can be converted into a grayscale by using A) CropImageFilter B) RGBImageFilter C) ImageConsumer A) ImageProducer 1.2 void printOut( int I ) { if (I==0) return; for(int i=I;i>0;i--) { System.out.println("Line " + i); } printOut(I-1); } What value should be passed to the method printOut, shown above, so that ten lines will be printed? A) 2 B) 3 C) 4 D) 5 1.3 If not assigned a value, a variable of type char has which default value? A) '\u0001' B) '\uffff' C) " " (space) D) '\u0000' A10.2-R3 Page 2 of 6 January, 2009 1.4 When is an object eligible for garbage collection? A) When an object becomes unreachable by any code B) When the finalize method is called on the object C) When an object goes out of scope D) When the system runs out of virtual memory 1.5 What would be the output from the following code? public class Thread373 implements Runnable { boolean flag = false; public void start() {

if (!flag) System.out.println("Hello World"); } public static void main(String[] args) { Thread373 t373 = new Thread373(); t373.start(); } } A) Compilation succeeds, Hello World is printed out. B) Compilation succeeds, nothing is printed out. C) Compilation fails. D) Execute with warnings. 1.6 If you create a TextField with a constructor to set it to occupy 5 columns, what difference will it make if you use it with a proportional font (i.e. Times Roman) or a fixed pitch typewriter style font (Courier). A) With a fixed font, you will see 5 characters, with a proportional it will depend on the width of the characters. B) With a fixed font, you will see 5 characters; with a proportional it will cause the field to expand to fit the text. C) The columns setting do not affect the number of characters displayed. D) Both will show exactly 5 characters. 1.7 A class needs to be created that will store unique object elements. The elements need not be sorted but they must be unique. What interface might be most suitable to meet this need? A) Set B) List C) Map D) Vector 1.8 Using the File class the task can be performed is A) Change the current directory B) Return the name of the parent directory C) Delete a file D) Finds whether a file contains text or binary information 1.9 What will be output by the following line? System.out.println(Math.floor(-2.1)); A) -2 B) 2.0 C) -3 D) -3.0 1.10 Which of the following wrapper classes can not take a String in constructor? A) Boolean B) Integer C) Double D) Character 1.1 The control expression in an if statement must be: A) an expression with either the type boolean or integer with value 0 or 1 B) an expression with either the type boolean or integer C) an expression with type boolean D) an expression with type integer 1.2 Which type of Statements can execute parameterized queries? A) PreparedStatement B) ParameterizedStatement C) ParameterizedStatement and CallableStatement D) All kinds of Statements

1.3 Which of the following is not an advantage of using inheritance? A) Enhancements to a derived class will automatically be applied to base class B) Code that is shared between classes needs to be written only once C) Similar classes can be made to behave consistently D) One big superclass can be used instead of many little classes 1.4 The methods wait( ) and notify( ) are defined in A) java.lang.Runnable B) java.lang.Object C) java.lang.Thread D) java.lang.ThreadGroup A10.2-R3 Page 2 of 5 January, 2010 1.5 What will be the output of the following code? public class AQuestion{ private int i = giveMeJ( ); private int j = 10; private int giveMeJ( ){ return j; } public static void main(String args[ ]){ System.out.println((new AQuestion( )).i); } } A) Compiler error complaining about access restriction of private variables of AQuestion B) Compiler error complaining about forward referencing C) No Compilation error - The output is 10 D) No Compilation error - The output is 0 1.6 To print the value of a variable "x" of type int, which of the following expressions can be used: A) System.out.println("x = " + String.valueOf(x)); B) System.out.println("x = " + Integer.toString(x)); C) System.out.println("x = " + (new Integer(x)).toString()); D) All of the above 1.7 The use of protected keyword to a member in a class will restrict its visibility as follows: A) Visible in all classes in the same package and subclasses in other packages B) Visible only in the class and its subclass in the same package C) Visible only inside the package D) Visible only in the class, where it is declared 1.8 What is the main feature of a TextArea? A) A TextArea can handle multiple lines of text B) A TextArea can be used for output C) TextArea is not a class D) TextAreas are used for displaying graphics 1.9 The setBackground( ) method is part of one of the following class in java.awt package: A) Object B) Component C) Container D) Applet 1.10 To run Java program, which of the following is required? A) Java language specification B) Java API C) Java JDK D) Java IDE 1.1 Which of the following assignments is illegal in Java? A) subclass_reference = subclass_object B) subclass_reference = superclass_object

C) superclass_reference = subclass_object D) superclass_reference = superclass_object 1.2 What will be the output, if any, of the following code segment? class Min{ public static void main(String args [ ]) { int min = 30; min(min, 20, 10); System.out.println(_ Minimum of 10, 20 ad 30 is _ + min); } static void min(int min, int a, int b) { if (a > b) min = b; else min = a; } } A) 10 B) 20 C) 30 D) Program will not compile. A10.2-R3 Page 1 of 5 July, 2006 1.3 Which of the following line will not compile assuming b1, b2 and b3 are byte variables and j is int variable? A) b1 = 3; B) b3 = b1 * b2; C) b3 = 10 * b1; D) b2 = (byte) j; 1.4 Which of the following is a loop construct that will always be executed once? A) switch B) for C) while D) do . while 1.5 Which of the following statements is false? A) We cannot create objects of abstract classes. B) The abstract methods of an abstract class must be defined in its subclass. C) Constructors cannot be abstract. D) Static methods can also be abstract. 1.6 The exception thrown by the read() method of InputStream class is A) Exception B) FileNotFound C) ReadException D) IOException 1.7 On invoking repaint() method for a Component, the method invoked by AWT is A) draw() B) show() C) update() D) paint() 1.8 A colored image can be converted into a grayscale by using A) CropImageFilter B) RGBImageFilter C) ImageConsumer D) ImageProducer 1.9 Which of the following is not a wrapper class? A) Vector B) Character C) Boolean D) Integer 1.10 The class at the top of the AWT hierarchy is

A) Component B) Window C) Container D) Frame 1.1 Visualizing program components as objects is characteristics of which of the following language types? A) Object oriented programming language B) Machine language C) Command line operating system D) Procedural language 1.2 What will be the result of compilation for the following code? public class MyClass { final int i ; public static void main(String[ ] arguments) { System.out.println(new MyClass().i); } } A) Will print 0 B) Will give compile error C) Will give runtime error D) Will give syntax error 1.3 Which are the valid declarations for an integer literal? i) 0 ii) -5 iii) 0416 iv) 0xabcdef A) i) and ii) B) i), ii) and iii) C) iv) D) All of the above A10.2-R3 Page 2 of 5 July, 2007 1.4 A subclass is also called as A) inner class B) nested class C) derived class D) hidden class 1.5 What will be the outcome of executing following code? class MyClass { public static void main (String args[ ]) { String s1[ ] = new String[5]; String str = s1[0].toUpperCase(); System.out.println(str); } } A) Will print null B) Will give NullPointerException C) Will not compile D) Will print NULL 1.6 Which of the following values you can assign to variable of type char? i) 'A'

ii) 9 iii) "Hello" iv) 12.3 A) i) and ii) B) i), ii) and iii) C) i) D) None of the above 1.7 Command to execute a compiled java program is A) run B) execute C) javac D) java 1.8 Attribute of an Object is also known as its A) State B) Method C) Behavior D) Procedures 1.9 Which of the following method is not defined by the Applet class? A) init( ) B) paint( ) C) start( ) D) none of the above 1.10 Java language has support for which of the following types of comments A) block, line and javadoc B) javadoc, literal and string C) javadoc, char and string D) single, multiple and quote 1.1 Which of the following best describes the synchronized keyword? A) It allows more than one Thread to access a method simultaneously. B) It allows more than one Thread to obtain the Object lock on a reference. C) It means only one thread at a time can access a method or block of code. D) It gives the exclusive access to the monitor. 1.2 If q1 and q2 are objects of a Test class, then q1. equals(q2) A) is true if q1 and q2 are references to the same test object. B) is a syntax error since equals is not defined in the test class. C) is true if q1 and q2 both store the same values. D) is never true. 1.3 What will the output of the following code? public class Test { public static void main(String[] args){ int j = 0; int i = ++j + j * 5; System.out.println(i); } } A) 0 B) 1 C) 5 D) 6 1.4 What is garbage collection in the context of Java? A) When all references to an object are gone, the memory used by the object is automatically reclaimed. B) The operating system periodically deletes all of the Java files available on the system.

C) Any package imported in a program and not used is automatically deleted. D) The JVM checks the output of any Java program and deletes anything that doesnt make sense. A10.2-R3 Page 1 of 5 July, 2008 A) interface A { void print() { }; } B) interface A { void print(); } C) abstract interface A { print(); } D) abstract interface A { abstract void print() { }; } 1.6 Which of the following object is a contained or transport mechanism to send/execute (normally) SQL statements and retrieve any results via its associated Connection? A) DriverManager B) Statement C) DatabaseMetaData D) Driver 1.7 What exception type does the following program throw? public class Test { public static void main(String[] args) { Object o = null; System.out.println(o); } } A) ArithmeticException B) NullReferencesException C) StringIndexOutOfBoundsException D) No exception 1.8 What should you use to position a Button within an application Frame so that the size of the Button is NOT affected by the Frame size? A) a GridLayout B) the center area of a BorderLayout C) a FlowLayout D) the East or West area of a BorderLayout 1.9 Swing components that dont rely on native GUI are referred to as A) heavyweight components B) GUI components C) non-GUI components D) lightweight components 1.10 Which of the following gives a technical definition of the language that includes the syntax and semantics of the Java programming language? A) Java language specification B) Java API C) Java JDK D) Java IDE 1.1 Java supports the following feature(s) A) Object-Oriented B) Platform Independent C) Secure D) All of the above 1.2 JVM follows the role of A) An Interpreter B) A device you use to run Applets C) An emulator used to execute Java machine code on a native platform D) A plug-in to Microsoft Internet Explorer 1.3 Java allows secure programming by providing the following safety consideration

A) Data and methods are encapsulated and hence hidden B) Does not allow any pointer arithmetic, so no direct access to memory C) Garbage Collection helps in destroying objects that are not referred to for a period of time D) All of the above 1.4 A ________ is a request for an operation A) message B) method C) attribute D) constructor 1.5 ________ is a mechanism that permits a class to share the attributes and operations defined in one or more classes. A) polymorphism B) inheritance C) abstraction D) encapsulation 1.6 What is the correct ordering for import, class and package declarations when found in a single file? A) package, import, class B) class, import package C) import, package, class D) package, class, import 1.7 Where in a constructor, can you place a call to a constructor defined in the superclass? A) Anywhere B) The first statement in the constructor C) The last statement in the constructor D) You cannot call super in a constructor 1.8 An interface has methods that are declared ________. A) Final B) Static C) Abstract D) None of the above 1.9 What is the output of the following code String s1=Welcome; String s2=new String(s1); if(s1 == s2) System.out.println(s1 == s2); else if System.out.println(s1.equals() s2); A) s1 == s2 B) s1.equals() s2 C) code gives error D) none of the above 1.10 In order to cause the print(Graphics) method to execute, which of the following is the most appropriate method to call A) paint() B) repaint() C) paint(Graphics) D) update(graphics) 1.1 The minimum value of char type variable is A) \u0020

B) \u00ff C) D) \u0000 1.2 Which of the following is correct? A) int a = 16, a>>2 = 4 B) int b = -8, b>>1 = -4 C) int a = 16, a>>>2 = 4 D) All of the above 1.3 Consider the following code if ( number >= 0) if (number > 0) System.out.println(Number is positive); else System.out.println(Number is negative); What will be the output if number is equal to 0? A) Number is negative B) Number is positive C) Both A) and B) D) None of the above A10.1-R4 (New) Page 2 of 5 July, 2010 1.4 What is the error in the following class definition? abstract class MyTest { abstract sum (int x, int y) { } } A) Class header is not defined properly B) Constructor is not defined C) Method is not defined properly D) No error 1.5 Consider the following class definitions: class mathstest { Student student1; } class Student { String name; } This code represents: A) an is a relationship B) a has a relationship C) both D) neither 1.6 Which of the following methods belong to the String class? A) length( ) B) compareTo() C) equals( ) D) All of the above 1.7 When repaint( ) is invoked for a component, the AWT invokes the ________ method. A) draw( ) B) update( ) C) paint( ) D) show( ) 1.8 Partitions in activity diagram are basically known as ________. A) Grouplens

B) Swimlens C) Workflow D) None 1.9 The deployment diagram represents ________ view of a use case model. A) Physical B) Logical C) Process D) All 1.10 The setBackground( ) method is part of the class ________. A) Graphics B) Applet C) Component D) Container 1.1. Which command is used to compile a Java source file? A) compilejava B) javacompiler C) javac D) javacmp 1.2. Which of the following is not a reserved keywords in Java? A) finally B) volatile C) abstract D) that 1.3. Java allows programmers to develop the following: A) Applets, applications and Servlets. B) Applets and applications. C) Applets, applications, Servelets, JavaBeans and Distributed objects. D) None of the above. 1.4. The advantages of abstraction is that it: A) Focuses on the problem at hand. B) Identifies the essential characteristics and the action required. C) Helps eliminate redundant detail. D) All of the above. 1.5. The process of hiding the attributes, methods or details of implementation is known as ________. A) Polymorphism B) Data Abstraction C) Inheritance D) Data Encapsulation 1.6. An interface has methods that are ________. A) final B) static C) abstract D) none of the above 1.7. Attempting to access a character that is outside the bounds of a StringBuffer results in a A) ArrayIndexOutOfBoundsException B) StringOverFlowException C) StringException D) StringIndexOutOfBoundsException 1.8. Methods defined by Math class are A) static double random() B) static double sin(double arg)

C) static double toDegrees(double angle) D) All of the above 1.9. Consider the following code snippet String s1=new String("JComponent"); System.out.println(s1.length()); What is printed? A) 9 B) 10 C) JCompnent D) s1 1.10. Which of the following is not a byte stream class? A) FilterlnputStream B) PipedOutputStream C) InputStreamReader D) RandomAceessFile

You might also like