Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Question No :1 StringBuffer objects once created can not be modified (Choose correct one from multiple below) 1. true 2. false 3. none of the above 4. none of the above correct is :2 Explanations :No Explanation available -----------------------------------------------------------------------------Question No :2 Which of the following are Java modifiers? 1) public 2) private 3) friendly 4) transient 5) vagrant (Choose correct one from multiple below) 1. 1,3,5 2. 1,2,4 3. 1,2,5 4. 1,2,3 correct is :2 -----------------------------------------------------------------------------Question No :3 What will be the result of executing the following code? public static void main(String args[]) { char digit = 'a'; for (int i = 0; i < 10; i++) { switch (digit) { case 'x' : { int j = 0; System.out.println(j); } default : { int j = 100; System.out.println(j); } } } int i = j; System.out.println(i); } (Choose correct one from multiple below) 1. 100 will be printed 10 times and then there will be a runtime exception. 2. The code will not compile because the variable i cannot be declared twice within the main() method. 3. The code will not compile because the variable j cannot be declared twice within the switch statement. 4. None of these. correct is :4 -----------------------------------------------------------------------------Question No :4 class c1 { public void m1(Object o1) { System.out.println("object"); } public void m1(String o1) { System.out.println("string"); } public int m1(int c) { return c; } public static void main(String a[]) { c1 ob1=new c1(); ob1.m1("hai"); } } (Choose correct one from multiple below) 1. print object 2. prints string 3. compile time error 4. non of the above correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :5 class C{ static int f1(int i) { System.out.print(i + ","); return 0; } public static void main (String[] args) { int i = 0; i = i++ + f1(i); System.out.print(i); }} (Choose correct one from multiple below) 1. Prints: 0,0 2. Prints: 1,0 3. Prints: 0,1 4. Compile-time error correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :6 What will happen when you attempt to compile and run this code? class Base{ public final void amethod(){ System.out.println("amethod"); } } public class Fin extends Base{ public static void main(String argv[]){ Base b = new Base(); b.amethod(); } } (Choose correct one from multiple below) 1. Compile time error indicating that a class with any final methods must be declared final itself 2. Compile time error indicating that you cannot inherit from a class with final methods 3. Run time error indicating that Base is not defined as final 4. Success in compilation and output of "amethod" at run time correct is :4 -----------------------------------------------------------------------------Question No :7 Which of the following statements about threading are true 1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable 2) You can obtain a mutually exclusive lock on any object 3) A thread can obtain a mutually exclusive lock on an object by calling a synchronized method on that object. 4) Thread scheduling algorithms are platform dependent (Choose correct one from multiple below) 1. 2,3,4 2. 1,2,3,4 3. 1,3 4. 3 correct is :1 -----------------------------------------------------------------------------Question No :8 What will be printed when you execute the following code? class X { Y b = new Y(); X() { System.out.print("X"); } } class Y { Y() { System.out.print("Y"); } } public class Z extends X { Y y = new Y(); Z() { System.out.print("Z"); } public static void main(String[] args) { new Z(); } } (Choose correct one from multiple below) 1. Z 2. YZ 3. XYZ 4. YXYZ correct is :4 -----------------------------------------------------------------------------Question No :9 What will happen when you attempt to compile and run the following code with the command line "hello there" public class Arg{String[] MyArg; public static void main(String argv[]){ MyArg=argv; } public void amethod(){ System.out.println(argv[1]); } } (Choose correct one from multiple below) 1. Compile time error 2. Compilation and output of "hello" 3. Compilation and output of "there" 4. None of the above correct is :1 -----------------------------------------------------------------------------Question No :10 How does the set collection deal with duplicate elements? (Choose correct one from multiple below) 1. An exception is thrown if you attempt to add an element with a duplicate value 2. The add method returns false if you attempt to add an element with a duplicate value 3. A set may contain elements that return duplicate values from a call to the equals method 4. Duplicate values will cause an error at compile time correct is :2 -----------------------------------------------------------------------------Question No :11 An Interface can never be private or protected. (Choose correct one from multiple below) 1. true 2. false 3. None 4. 1 or 2 correct is :1 -----------------------------------------------------------------------------Question No :12 abstract class C1{ public void m1(){ //1 }} abstract class C2{ public void m2(){ //2 }} (Choose correct one from multiple below) 1. compile time error at line1 2. compile time error at line2 3. The code compiles fine 4. None of the above correct is :3 Explanations :since the class C2 is abstract it can contain abstract methods -----------------------------------------------------------------------------Question No :13 (Choose correct one from multiple below) 1. compile time error at line 1 2. compile time error at line 2 3. Runtime exception 4. None of the above correct is :1 -----------------------------------------------------------------------------Question No :14 Which of the following most closely describes the process of overriding? (Choose correct one from multiple below) 1. A class with the same name replaces the functionality of a class defined earlier in the hierarchy 2. A method with the same name completely replaces the functionality of a method earlier in the hierarchy 3. A method with the same name but different parameters gives multiple uses for the same method name 4. A class is prevented from accessing methods in its immediate ancestor correct is :2 Explanations :Option 3 is more like a description of overloading. I like to remind myself of the difference between overloading and overriding in that an overriden method is like something overriden in the road, it is squashed, flat no longer used and replaced by something else. An overloaded method has been given extra work to do (it is loaded up with work), but it is still being used in its original format. This is just my little mind trick and doesn't match to anything that Java is doing -----------------------------------------------------------------------------Question No :15 Which of the following are methods of the Thread class? 1) yield() 2) sleep(long msec) 3) go() 4) stop() (Choose correct one from multiple below) 1. 1,3,4 2. 1,2,4 3. 1,3 4. 3 correct is :2 -----------------------------------------------------------------------------Question No :16 What will be output by the following line? System.out.println(Math.floor(-2.1)); (Choose correct one from multiple below) 1. -2.0 2. -3.0 3. 2.0 4. 3.0 correct is :2 -----------------------------------------------------------------------------Question No :17 What will be printed out if you attempt to compile and run the following code? int i=9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); } (Choose correct one from multiple below) 1. default 2. default, zero 3. error default clause not defined 4. no output displayed correct is :2 -----------------------------------------------------------------------------Question No :18 Given the following main method in a class called Cycle and a command line of java Cycle one two what will be output? public static void main(String bicycle[]){ (Choose correct one from multiple below) 1. one 2. two 3. NULL System.out.println(bicycle[0]);} 4. None correct is :1 -----------------------------------------------------------------------------Question No :19 What will happen when you attempt to compile and run this code? public class Mod{ public static void main(String argv[]){} public static native void amethod(); } (Choose correct one from multiple below) 1. Error at compilation: native method cannot be static 2. Error at compilation native method must return value 3. Compilation but error at run time unless you have made code containing native amethod available 4. Compilation and execution without error correct is :4 -----------------------------------------------------------------------------Question No :20 What is the value of y? int y = 19 % 4; (Choose correct one from multiple below) 1. 3 2. 4 3. 2 4. Compile Error correct is :1 -----------------------------------------------------------------------------Question No :21 if("String".replace('t','T') == "String".replace('t','T')) System.out.println("Equal"); else System.out.println("Not Equal"); (Choose correct one from multiple below) 1. will Print Equal 2. will Print Not Equal 3. compile time error 4. none of the above correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :22 What will happen when you attempt to compile and run the following code? public class Static { static { int x = 5; } static int x,y; public static void main(String args[]) { x--; myMethod(); System.out.println(x + y + ++x); } public static void myMethod() { y = x++ + ++x; } } (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 7 correct is :4 -----------------------------------------------------------------------------Question No :23 What will be output by the following line? System.out.println(Math.floor(-2.1)); (Choose correct one from multiple below) 1. -2.0 2. -3.0 3. 2.0 4. 3.0 correct is :2 -----------------------------------------------------------------------------Question No :24 What will happen when you attempt to compile and run the following code? interface MyInterface { } public class MyInstanceTest implements MyInterface { static String s; public static void main(String args[]) { MyInstanceTest t = new MyInstanceTest(); if(t instanceof MyInterface) { System.out.println("I am true interface"); } else { System.out.println("I am false interface"); } if(s instanceof String) { System.out.println("I am true String"); } else { System.out.println("I am false String"); } } } (Choose correct one from multiple below) 1. Prints : "I am true interface" followed by " I am true String" 2. Prints : "I am false interface" followed by " I am false String" 3. Prints : "I am true interface" followed by " I am false String" 4. Runtime error correct is :3 -----------------------------------------------------------------------------Question No :25 class C { static void m1(Object x) {System.out.print("Object");} static void m1(String x) {System.out.print("String");} public static void main(String[] args) { m1(null); }} (Choose correct one from multiple below) 1. Prints Object 2. Prints String 3. compiletime error 4. None of the above correct is :2 Explanations :The more specific of the two, m(String x), is chosen -----------------------------------------------------------------------------Question No :26 Which of the following statements are true? 1) A method in an interface must not have a body 2) A class may extend one other class plus at most one interface 3) A class may extends at most one other class plus implement many interfaces 4) An class accesses an interface via the keyword uses (Choose correct one from multiple below) 1. 1 and 2 2. 2 and 3 3. 3 and 4 4. 1 and 3 correct is :4 Explanations :A class accesses an interface using the implements keyword (not uses) -----------------------------------------------------------------------------Question No :27 abstract class A {} // 1 transient class B {} // 2 private class C {} // 3 static class D {} // 4 Which of these declarations will not produce a compile-time error? (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 4 correct is :1 Explanations :The modifiers, private and static, can be applied to a nested class, but can not be applied to a class that is not nested transient is allowed only for variables. -----------------------------------------------------------------------------Question No :28 class C { private String get ( String str ) { try { throw new Exception ( ) ; return str ; } catch ( Exception e ) { return null ; } } public static void main ( String peace [ ] ) { try { System.out.println ( ( new C ( ) ).get ( " C " ) ) ; } catch ( Exception e ) { System.out.println( "Exception" ) ; } } }; (Choose correct one from multiple below) 1. compile time error 2. prints Exception 3. the code compiles and runs fine 4. none of the above correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :29 What best describes the appearance of an application with the following code? import java.awt.*; public class FlowAp extends Frame{ public static void main(String argv[]){ FlowAp fa=new FlowAp(); fa.setSize(400,300); fa.setVisible(true); } FlowAp(){ add(new Button("One")); add(new Button("Two")); add(new Button("Three")); add(new Button("Four")); }//End of constructor}//End of Application } (Choose correct one from multiple below) 1. A Frame with buttons marked One to Four placed on each edge. 2. A Frame with buutons marked One to four running from the top to bottom 3. A Frame with one large button marked Four in the Centre 4. An Error at run time indicating you have not set a LayoutManager correct is :3 -----------------------------------------------------------------------------Question No :30 What will happen when you attempt to compile and run the following code? import java.io.*; class ExBase{ abstract public void martley(){ } } public class MyEx extends ExBase{ public static void main(String argv[]){ DataInputStream fi = new DataInputStream(System.in); try{ fi.readChar(); }catch(IOException e){ System.exit(0); } finally {System.out.println("Doing finally");} } } (Choose correct one from multiple below) 1. Compile time error 2. It will run, wait for a key press and then exit 3. It will run, wait for a keypress, print "Doing finally" then exit 4. At run and immediately exit correct is :1 Explanations :It wil produce an error like "Abstract and native method can't have a body. This is typical of the more misleading question where you might think it is asking you about the circumstances under which the finally clause runs, but actually it is about something else. -----------------------------------------------------------------------------Question No :31 class c2 { { System.out.println("initializer"); } public static void main(String a[]) { System.out.println("main"); c2 ob1=new c2(); } } (Choose correct one from multiple below) 1. prints main and initializer 2. prints initializer and main 3. compile time error 4. None of the above correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :32 Which data type is wider for the purpose of casting: float or long? (Choose correct one from multiple below) 1. float 2. long 3. none of the above 4. none of the above correct is :1 Explanations :float is wider than long, because the entire range of long fits within the range of float. -----------------------------------------------------------------------------Question No :33 interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 } (Choose correct one from multiple below) 1. compiletime error at lines 1,2,3,4 2. compiletime error at line 3 3. compiletime error at line 1 4. compiletime error at lines 3,4 correct is :4 Explanations :all methods declared within an interface are implicitly public, a weaker access level can not be declared. -----------------------------------------------------------------------------Question No :34 What is the result when you compile and run the following code? public class ThrowsDemo { static void throwMethod() { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); } public static void main(String args[]) { try { throwMethod(); } catch (IllegalAccessException e) { System.out.println("Caught " + e); } } } (Choose correct one from multiple below) 1. Compilation error 2. Runtime error 3. Compile successfully, nothing is printed. 4. Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo correct is :1 -----------------------------------------------------------------------------Question No :35 When a byte is added to a char, what is the type of the result? (Choose correct one from multiple below) 1. byte 2. int 3. long 4. non of the above correct is :2 Explanations :The result of all arithmetic performed with the binary operators (not the assignment operators) is an int, a long, a float, or a double. Here byte and char are promoted to int, so the result is an int. -----------------------------------------------------------------------------Question No :36 The relationship between a class and its superclass is (Choose correct one from multiple below) 1. has-a 2. is -a 3. None of the above 4. none of the above correct is :2 Explanations :No Explanation available -----------------------------------------------------------------------------Question No :37 How do you indicate where a component will be positioned using Flowlayout? 1) North, South,East,West 2) Assign a row/column grid reference 3) Pass a X/Y percentage parameter to the add method 4) Do nothing, the FlowLayout will position the component (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 4 correct is :4 -----------------------------------------------------------------------------Question No :38 class C { public static void main(String a[]) { C c1=new C(); C c2=m1(c1); C c3=new C(); c2=c3; //6 anothermethod(); } static C m1(C ob1){ ob1 =new C(); return ob1; } } After line 6, how many objects are eligible for garbage collection? (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 4 correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :39 What is the output? class Bird { boolean b; public Bird() { System.out.println(b); } public static void main(String[] args){ Bird b = new Bird(); } } (Choose correct one from multiple below) 1. true 2. false 3. garbage 4. none of the above correct is :2 -----------------------------------------------------------------------------Question No :40 Which most closely matches a description of a Java Map? (Choose correct one from multiple below) 1. A vector of arrays for a 2D geographic representation 2. A class for containing unique array elements 3. A class for containing unique vector elements 4. An interface that ensures that implementing classes cannot contain duplicate keys correct is :4 -----------------------------------------------------------------------------Question No :41 What will be output by the following line? System.out.println(Math.floor(-2.1)); (Choose correct one from multiple below) 1. -2.0 2. -3.0 3. 2.0 4. 3.0 correct is :2 ------------------------------------------------------------------------------ Question No :42 A signed data type has an equal number of non-zero positive and negative values available (Choose correct one from multiple below) 1. true 2. false 3. none of the above 4. none of the above correct is :2 Explanations :The range of negative numbers is greater by 1 than the range of positive numbers -----------------------------------------------------------------------------Question No :43 Which of the following lines will print false? 1.public class MyClass 2.{ 3.static String s1 = "I am unique!"; 4.public static void main(String args[]) 5.{ 6.String s2 = "I am unique!"; 7.String s3 = new String(s1); 8.System.out.println(s1 == s2); 9.System.out.println(s1.equals(s2)); 10.System.out.println(s3 == s1); 11.System.out.println(s3.equals(s1)); 12.System.out.println(TestClass.s4 == s1); 13.} 14.} 15. 16.class TestClass 17.{ 18.static String s4 = "I am unique!"; 19.} (Choose correct one from multiple below) 1. Lines 10 and 12 2. Line 12 only 3. Line 8 and 10 4. None of these correct is :4 -----------------------------------------------------------------------------Question No :44 What will happen when you attempt to compile and run the following code? import java.io.*; class ExBase{ abstract public void martley(){ } } public class MyEx extends ExBase{ public static void main(String argv[]){ DataInputStream fi = new DataInputStream(System.in); try{ fi.readChar(); }catch(IOException e){ System.exit(0); } finally {System.out.println("Doing finally");} } } (Choose correct one from multiple below) 1. Compile time error 2. It will run, wait for a key press and then exit 3. It will run, wait for a keypress, print "Doing finally" then exit 4. At run and immediately exit correct is :1 Explanations :It wil produce an error like "Abstract and native method can't have a body. This is typical of the more misleading question where you might think it is asking you about the circumstances under which the finally clause runs, but actually it is about something else. -----------------------------------------------------------------------------Question No :45 1. StringBuffer s1 = new StringBuffer("abc"); 2. StringBuffer s2 = s1; 3. StringBuffer s3 = new StringBuffer("abc"); How many objects are created ? (Choose correct one from multiple below) 1. 0 2. 1 3. 2 4. 3 correct is :4 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :46 What will be the result when you try to compile and run the following code? private class Base{ Base(){int i = 100; System.out.println(i); } } public class Pri extends Base{ static int i = 200; public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); } } (Choose correct one from multiple below) 1. Error at compile time 2. 200 3. 100 followed by 200 4. 100 correct is :1 -----------------------------------------------------------------------------Question No :47 int count=0, i=0; do { count *= i; i++; if(count == 1) continue; count++; } while(i<3); System.out.println(count); What is the output? (Choose correct one from multiple below) 1. 4 2. 2 3. 3 4. 5 correct is :3 -----------------------------------------------------------------------------Question No :48 System.out.println("String".substring(0,4)); This statement will Print (Choose correct one from multiple below) 1. will print "Strin" 2. will print "Stri" 3. will cause compiler error 4. none of the above correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :49 An abstract class must have at least one abstract method (Choose correct one from multiple below) 1. true 2. true 3. none of the above 4. none of the above correct is :2 Explanations :An abstract without abstract methods is allowed -----------------------------------------------------------------------------Question No :50 class C{ public static void main (String[] args) { byte b1=33; //1 b1++; //2 byte b2=55; //3 b2=b1+1; //4 System.out.println(b1+""+b2); }} (Choose correct one from multiple below) 1. compile time error at line 2 2. compile time error at line 4 3. prints 34,56 4. runtime exception correct is :2 Explanations :b1+1 returns an integer value which can not be assigned to a byte variable ------------------------------------------------------------------------------ Question No :51 The Throwable class is the superclass of all exceptions in the Java language. (Choose correct one from multiple below) 1. true 2. false 3. none of the above 4. none of the above correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :52 • Each element must be unique • Duplicate elements must not replace old elements. • Elements are not key/value pairs. • Accessing an element can be almost as fast as performing a similar operation on an array. Which of these classes provide the specified features? (Choose correct one from multiple below) 1. LinkedList 2. TreeMap 3. HashMap 4. HashSet correct is :4 Explanations :No explanation available -----------------------------------------------------------------------------Question No :53 Which of the following most closely describes the process of overriding? (Choose correct one from multiple below) 1. A class with the same name replaces the functionality of a class defined earlier in the hierarchy 2. A method with the same name completely replaces the functionality of a method earlier in the hierarchy 3. A method with the same name but different parameters gives multiple uses for the same method name 4. A class is prevented from accessing methods in its immediate ancestor correct is :2 Explanations :Option 3 is more like a description of overloading. I like to remind myself of the difference between overloading and overriding in that an overriden method is like something overriden in the road, it is squashed, flat no longer used and replaced by something else. An overloaded method has been given extra work to do (it is loaded up with work), but it is still being used in its original format. This is just my little mind trick and doesn't match to anything that Java is doing -----------------------------------------------------------------------------Question No :54 What results from the following code? 1.class MyClass 2.{ 3.void myMethod(int i) {System.out.println("int version");} 4.void myMethod(String s) {System.out.println("String version");} 5.public static void main(String args[]) 6.{ 7.MyClass obj = new MyClass(); 8.char ch = 'c'; 9.obj.myMethod(ch); 10.} 11.} (Choose correct one from multiple below) 1. Line 4 will not compile as void methods can't be overridden. 2. An exception at line 9. 3. Line 9 will not compile as there is no version of myMethod which takes a char as argument. 4. The code compiles and produces output: int version. correct is :4 -----------------------------------------------------------------------------Question No :55 (Choose correct one from multiple below) 1. prints 34 2. prints 33 3. compile time error 4. Runtime exception correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :56 class H { public static void main (String[] args) { String s1 = "HHH"; StringBuffer sb2 = new StringBuffer(s1); System.out.print(sb2.equals(s1) + "," + s1.equals(sb2)); }} (Choose correct one from multiple below) 1. Prints: false,false 2. Prints: true,false 3. Prints: false,true 4. Prints: true,true correct is :1 Explanations :s1 and sb2 are pointing to different object references -----------------------------------------------------------------------------Question No :57 What is the value of p? int p = 10 / 3; (Choose correct one from multiple below) 1. 3 2. 3.33333 3. 0 4. 1 correct is :1 -----------------------------------------------------------------------------Question No :58 The constructor for the Math class is private, so it cannot be instaniated (Choose correct one from multiple below) 1. true 2. false 3. none of the above 4. none of the above correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :59 You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.? public class MyAr{ public static void main(String argv[]){ int[] i = new int[5]; System.out.println(i[5]); } } (Choose correct one from multiple below) 1. An error at compile time 2. An error at run time 3. The value 0 will be output 4. The string "null" will be output correct is :2 -----------------------------------------------------------------------------Question No :60 Which of the following best describes the use of the synchronized keyword? (Choose correct one from multiple below) 1. Allows two process to run in paralell but to communicate with each other 2. Ensures only one thread at a time may access a method or object 3. Ensures that two or more processes will start and end at the same time 4. Ensures that two or more Threads will start and end at the same time correct is :2 -----------------------------------------------------------------------------Question No :61 • Each element must be unique • Duplicate elements must not replace old elements. • Elements are not key/value pairs. • Accessing an element can be almost as fast as performing a similar operation on an array. Which of these classes provide the specified features? (Choose correct one from multiple below) 1. LinkedList 2. TreeMap 3. HashMap 4. HashSet correct is :4 Explanations :No explanation available -----------------------------------------------------------------------------Question No :62 interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 abstract void f5(); // 5 } (Choose correct one from multiple below) 1. line 1,2,3,4 2. line 3,4 3. line 3 4. line 2,3,4 correct is :2 Explanations :all methods declared within an interface are implicitly public, a weaker access level can not be declared -----------------------------------------------------------------------------Question No :63 Which of the following statements are true? (Choose correct one from multiple below) 1. Static methods cannot be overriden to be non static 2. Static methods cannot be declared as private 3. Private methods cannot be overloaded 4. An overloaded method cannot throw exceptions not checked in the base class correct is :1 -----------------------------------------------------------------------------Question No :64 What is the result when you compile and run the following code? public class Test { public void method() { for(int i = 0; i < 3; i++) { System.out.print(i); } System.out.print(i); } } (Choose correct one from multiple below) 1. 0122 2. 0123 3. Compilation error 4. None of these correct is :3 -----------------------------------------------------------------------------Question No :65 class C { public static void main(String[] args) { int i1=1; switch(i1){ case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); }}} (Choose correct one from multiple below) 1. prints one two three 2. prints one 3. compile time error 4. Runtime exceptionf correct is :1 Explanations :There is no break statement in case 1 so it causes the below case statements to execute regardless of their values -----------------------------------------------------------------------------Question No :66 class A extends Thread { private int i; public void run() {i = 1;} public static void main(String[] args) { A a = new A(); a.run(); System.out.print(a.i); }} How many threads are created in this Program? (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 0 correct is :1 Explanations :Main thread is a thread and calling run methods will not creat thread. -----------------------------------------------------------------------------Question No :67 abstract class vehicle{ abstract public void speed(); } class car extends vehicle{ public static void main (String args[]) { vehicle ob1; ob1=new car(); //1 }} (Choose correct one from multiple below) 1. compiletime error at line 1 2. forces the class car to be declared as abstract 3. Runtime Exception 4. None of the above correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :68 Given the following class public class Ombersley{ public static void main(String argv[]){ boolean b1 = true; if((b1 ==true) || place(true)){ System.out.println("Hello test"); } } public static boolean place(boolean location){ if(location==true){ System.out.println("kum"); } System.out.println("news"); return true; } } What will happen when you attempt to compile and run it? (Choose correct one from multiple below) 1. Compile time error 2. Output of "Hello test" 3. Output of Borcetshire and Powick followed by "Hello test" 4. No output correct is :2 Explanations :This code is an example of a short circuited operator. Because the first operand of the || (or) operator returns true Java sees no reason to evaluate the second. Whatever the value of the second the overall result will always be true. Thus the method called place is never called. -----------------------------------------------------------------------------Question No :69 Which of the following statements are true? 1) All of the variables in an interface are implicitly static 2) All of the variables in an interface are implicitly final 3) All of the methods in an interface are implicitly abstract 4) A method in an interface can access class level variables (Choose correct one from multiple below) 1. 1 ,2 and 3 2. 1 ,2 ,3 and 4 3. 1 and 4 4. 2 and 4 correct is :1 Explanations :All the variables in an interface are implicitly static and final. Any methods in an interface have no body, so may not access any type of variable -----------------------------------------------------------------------------Question No :70 Which of the following statement is wrong? (Choose correct one from multiple below) 1. System.out.println( -1 >>> 2);will output a result larger than 10 2. System.out.println( -1 >>> 2); will output a positive number 3. System.out.println( 2 >> 1); will output the number 1 4. System.out.println( 1 <<< 2); will output the number 4 correct is :4 -----------------------------------------------------------------------------Question No :71 Which of the following best describes the use of the synchronized keyword? (Choose correct one from multiple below) 1. Allows two process to run in paralell but to communicate with each other 2. Ensures only one thread at a time may access a method or object 3. Ensures that two or more processes will start and end at the same time 4. Ensures that two or more Threads will start and end at the same time correct is :2 -----------------------------------------------------------------------------Question No :72 interface I { //1 public class Inner { ///2 Inner ( ) { System .out . println ( "Inner Created" ) ; } }; }; (Choose correct one from multiple below) 1. compile time error at line 1 2. compile time error at line 2 3. the code compiles fine 4. none of the above correct is :3 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :73 class C { public static void main(String[] args) { double d1 = Math.floor(0.5); double d2 = Math.floor(1.5); System.out.print(d1 + "," + d2); }} (Choose correct one from multiple below) 1. Prints: 0.0,1.0 2. Prints: 0.0,2.0 3. Prints: 1.0,1.0 4. Prints: 1.0,2.0 correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :74 Which of the following is not Java modifier? 1) public 2) private 3) friendly 4) transient (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 4 correct is :3 -----------------------------------------------------------------------------Question No :75 A signed data type has an equal number of non-zero positive and negative values available (Choose correct one from multiple below) 1. true 2. false 3. none of the above 4. none of the above correct is :2 Explanations :The range of negative numbers is greater by 1 than the range of positive numbers -----------------------------------------------------------------------------Question No :76 class bike { } class arr extends bike{ public static void main(String[] args) { arr[] a1=new arr[2]; bike[] a2; a2=a1; //3 arr[] a3; a3=a1; //5 }} (Choose correct one from multiple below) 1. compile time error at line 3 2. compile time error at line 5 3. Runtime exception 4. The code runs fine correct is :4 Explanations :bike is the superclass of arr.so they are compatible(superobject=subobject) but subobject=superobject not allowed -----------------------------------------------------------------------------Question No :77 Given the following declarations String s1=new String("Hello"); String s2=new String("there"); String s3=new String(); Which of the following are legal operations? (Choose correct one from multiple below) 1. s3=s1 + s2; 2. s3=s1-s2; 3. s3=s1 & s2; 4. s3=s1 && s2 correct is :1 -----------------------------------------------------------------------------Question No :78 If you run the code below, what gets printed out? public class Test { public static void main(String argv[]){ String s=new String("Bicycle"); int iBegin=1; char iEnd=3; System.out.println(s.substring(iBegin,iEnd)); } } (Choose correct one from multiple below) 1. Bic 2. icy 3. ic 4. error: no method matching substring(int,char) correct is :3 -----------------------------------------------------------------------------Question No :79 class command { public static void main (String[] a1) { System.out.println(a1.length()); //1 System.out.println(a1[0]); //2 System.out.println(a1); //3 //2 }} (Choose correct one from multiple below) 1. compile time error at line1 2. compile time error at line2 3. compile time error at line3 4. Runtime exception correct is :1 Explanations :length is not a method. it's a variable -----------------------------------------------------------------------------Question No :80 What will be printed out if you attempt to compile and run the following code ? int i=1; switch (i) { case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); default: System.out.println("default"); } (Choose correct one from multiple below) 1. one 2. one, default 3. one, two, default 4. default correct is :3 -----------------------------------------------------------------------------Question No :81 Which of the following are methods of the Thread class? 1) yield() 2) sleep(long msec) 3) go() 4) stop() (Choose correct one from multiple below) 1. 1,3,4 2. 1,2,4 3. 1,3 4. 3 correct is :2 -----------------------------------------------------------------------------Question No :82 What will be printed out if this code is run with the following command line? java myprog good morning public class myprog{ public static void main(String argv[]) { System.out.println(argv[2]); } } (Choose correct one from multiple below) 1. myprog 2. good 3. morning 4. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2" correct is :4 -----------------------------------------------------------------------------Question No :83 What is the output? class Bird { boolean b; public Bird() { System.out.println(b); } public static void main(String[] args){ Bird b = new Bird(); } } (Choose correct one from multiple below) 1. true 2. false 3. garbage 4. none of the above correct is :2 -----------------------------------------------------------------------------Question No :84 What is the value of y? int y = 2 % 4; (Choose correct one from multiple below) 1. 0 2. 2 3. 4 4. Compile Error correct is :2 -----------------------------------------------------------------------------Question No :85 How does the set collection deal with duplicate elements? (Choose correct one from multiple below) 1. An exception is thrown if you attempt to add an element with a duplicate value 2. The add method returns false if you attempt to add an element with a duplicate value 3. A set may contain elements that return duplicate values from a call to the equals method 4. Duplicate values will cause an error at compile time correct is :2 -----------------------------------------------------------------------------Question No :86 if(0.0 == -0.0) { System.out.println("true"); } else{ System.out.println("false"); } (Choose correct one from multiple below) 1. prints false 2. prints true 3. none of the above 4. none of the above correct is :2 Explanations :No Explanation available -----------------------------------------------------------------------------Question No :87 The______________ listener is notified when attributes are added to, removed from, or replaced in the Servlet context. (Choose correct one from multiple below) 1. Session Attribute 2. Servlet context attribute 3. Session Listeners 4. Session context Listeners correct is :2 -----------------------------------------------------------------------------Question No :88 Which of the following are methods of the Thread class? 1) yield() 2) sleep(long msec) 3) go() 4) stop() (Choose correct one from multiple below) 1. 1,3,4 2. 1,2,4 3. 1,3 4. 3 correct is :2 ------------------------------------------------------------------------------ Question No :89 What will be the result of executing the following code? 1. boolean a = true; 2. boolean b = false; 3. boolean c = true; 4. if (a == true) 5. if (b == true) 6. if (c == true) System.out.println("Some things are true in this world"); 7. else System.out.println("Nothing is true in this world!"); 8. else if (a && (b = c)) System.out.println("It's too confusing to tell what is true and what is false"); 9. else System.out.println("Hey this won't compile"); (Choose correct one from multiple below) 1. The code won't compile 2. "Some things are true in this world" will be printed 3. "Hey this won't compile" will be printed 4. None of these correct is :4 -----------------------------------------------------------------------------Question No :90 public static double sin(double angle) What are the units of the "angle" argument? (Choose correct one from multiple below) 1. Degrees 2. Radians 3. Both 4. None of the above correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :91 A signed data type has an equal number of non-zero positive and negative values available (Choose correct one from multiple below) 1. true 2. false 3. none of the above 4. none of the above correct is :2 Explanations :The range of negative numbers is greater by 1 than the range of positive numbers ------------------------------------------------------------------------------ Question No :92 What will happen when you attempt to compile and run the following code? int Output = 10; boolean b1 = false; if((b1 == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); } else { System.out.println("Not equal! " + Output); } (Choose correct one from multiple below) 1. Compilation error, attempting to perform binary comparison on logical data type. 2. Compilation and output of "We are equal 10". 3. Compilation and output of "Not equal! 20". 4. Compilation and output of "Not equal! 10". correct is :4 -----------------------------------------------------------------------------Question No :93 Which of the following statements are correct? 1) If multiple listeners are added to a component only events for the last listener added will be processed 2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order 3) Adding multiple listeners to a comnponent will cause a compile time error 4) You may remove as well add listeners to a component. (Choose correct one from multiple below) 1. 1 and 4 2. 1,2 and 3 3. 2 and 4 4. 2 and 3 correct is :3 -----------------------------------------------------------------------------Question No :94 Which of the following modifiers can be applied to a class that is not a nested class? (Choose correct one from multiple below) 1. public 2. protected 3. private 4. static correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :95 Which of the following statements are correct? 1) If multiple listeners are added to a component only events for the last listener added will be processed 2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order 3) Adding multiple listeners to a comnponent will cause a compile time error 4) You may remove as well add listeners to a component. (Choose correct one from multiple below) 1. 1 and 4 2. 1,2 and 3 3. 2 and 4 4. 2 and 3 correct is :3 -----------------------------------------------------------------------------Question No :96 Given the folowing classes which of the following will compile without error? interface IFace{} class CFace implements IFace{} class Base{} public class ObRef extends Base{ public static void main(String argv[]){ ObRef ob = new ObRef(); Base b = new Base(); Object o1 = new Object(); IFace o2 = new CFace(); } } 1)o1=o2; 2)b=ob; 3)ob=b; 4)o1=b; (Choose correct one from multiple below) 1. 1,2,4 2. 2,3,4 3. 1,3,4 4. 3,4 correct is :1 -----------------------------------------------------------------------------Question No :97 class A extends Thread { private int i; public void run() {i = 1;} public static void main(String[] args) { A a = new A(); a.run(); System.out.print(a.i); }} How many threads are created in this Program? (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 0 correct is :1 Explanations :Main thread is a thread and calling run methods will not creat thread. -----------------------------------------------------------------------------Question No :98 What will happen when you attempt to compile and run the following code? class Base { int i = 99; public void amethod() { System.out.println("Base.amethod()"); } Base() { amethod(); } } public class Derived extends Base { int i = -1; public static void main(String argv[]) { Base b = new Derived(); System.out.println(b.i); b.amethod(); } public void amethod() { System.out.println("Derived.amethod()"); } } (Choose correct one from multiple below) 1. Derived.amethod() -1 Derived.amethod() 2. Derived.amethod() 99 3. Derived.amethod() 99 4. Derived.amethod() correct is :2 -----------------------------------------------------------------------------Question No :99 Which data type is wider for the purpose of casting: float or long? (Choose correct one from multiple below) 1. float 2. long 3. none of the above 4. none of the above correct is :1 Explanations :float is wider than long, because the entire range of long fits within the range of float. -----------------------------------------------------------------------------Question No :100 Which statement is correct ? (Choose correct one from multiple below) 1. If super class has different constructor other then default then in the sub class you can use default constructor 2. If super class has different constructor other then default then in the sub class you can?t use default constructor 3. Both are true 4. none of the above correct is :2 -----------------------------------------------------------------------------Question No :101 import java.util.*; class C { final Vector v; C() { v=new Vector(); } C(int i) { } public void someMethod() { System.out.println(v.isEmpty()); } } (Choose correct one from multiple below) 1. compile time error 2. runtime exception 3. the code compiles and runs fine 4. none of the above correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :102 • Each element must be unique • Duplicate elements must not replace old elements. • Elements are not key/value pairs. • Accessing an element can be almost as fast as performing a similar operation on an array. Which of these classes provide the specified features? (Choose correct one from multiple below) 1. LinkedList 2. TreeMap 3. HashMap 4. HashSet correct is :4 Explanations :No explanation available -----------------------------------------------------------------------------Question No :103 Which of the following modifiers can be applied to a class that is not a nested class? (Choose correct one from multiple below) 1. public 2. protected 3. private 4. static correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :104 class command { public static void main (String[] a1) { System.out.println(a1.length()); //1 System.out.println(a1[0]); //2 System.out.println(a1); //3 //2 }} (Choose correct one from multiple below) 1. compile time error at line1 2. compile time error at line2 3. compile time error at line3 4. Runtime exception correct is :1 Explanations :length is not a method. it's a variable -----------------------------------------------------------------------------Question No :105 Given the code below, and making no other changes, which access modifiers (public, protected or private) can legally be placed before myMethod() on line 3? If line 3 is left as it is, which keywords can legally be placed before myMethod on line 8? 1.class HumptyDumpty 2.{ 3.void myMethod() {} 4.} 5. 6.class HankyPanky extends HumptyDumpty 7.{ 8.void myMethod() {} 9.} (Choose correct one from multiple below) 1. private or nothing(i.e. leaving it as it is) on line 3. Nothing(i.e. leaving it as it is) or protected or public on line 8. 2. public or protected on line 3. private or nothing(i.e. leaving it as it is) on line 8. 3. nothing(i.e. leaving it as it is) or protected or public on line 3. private or nothing(i.e. leaving it as it is) on line 8. 4. None of the above. correct is :1 -----------------------------------------------------------------------------Question No :106 What will be output by the following line of code? System.out.println(010|4); (Choose correct one from multiple below) 1. 12 2. 10 3. 11 4. 14 correct is :1 -----------------------------------------------------------------------------Question No :107 In the following pieces of code, A and D will compile without any error. True/False? A: StringBuffer sb1 = "abcd"; B: Boolean b = new Boolean("abcd"); C: byte b = 255; D: int x = 0x1234; E: float fl = 1.2; (Choose correct one from multiple below) 1. true 2. false 3. none of these 4. no idea correct is :2 -----------------------------------------------------------------------------Question No :108 Which of the following classes will not allow unsynchronized read operations by multiple threads? (Choose correct one from multiple below) 1. Vector 2. TreeMap 3. TreeSet 4. HashMap correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :109 class C { public static void main(String[] args) { char c1=65; switch(c1){ case 'A': System.out.println("one"); default: System.out.println("two"); case 'b': System.out.println("three"); }}} (Choose correct one from multiple below) 1. prints one twot hree 2. prints two three 3. compile time error 4. Runtime exception correct is :1 Explanations :char is a legal value for switch clause -----------------------------------------------------------------------------Question No :110 class base { base(int c) { System.out.println("base"); } } class Super extends base { Super() { System.out.println("super"); } public static void main(String [] a) { base b1=new Super(); } } (Choose correct one from multiple below) 1. compile time error 2. runtime exceptione 3. the code compiles and runs fine 4. None of the above correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :111 class C { public static void main(String[] args) { int i1=1; switch(i1){ case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); }}} (Choose correct one from multiple below) 1. prints one two three 2. prints one 3. compile time error 4. Runtime exceptionf correct is :1 Explanations :There is no break statement in case 1 so it causes the below case statements to execute regardless of their values ------------------------------------------------------------------------------ Question No :112 class C { public static void main ( String ka [ ] ) { Thread t = Thread . currentThread ( ) ; t . setPriority ( - 1 ) ; System . out . println ( " Done ! " ) ; } }; (Choose correct one from multiple below) 1. compile time error 2. Runtime Exception 3. The code compiles and runs fine 4. None of the above correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :113 Which of the following statements are true? 1) Constructors cannot have a visibility modifier 2) Constructors can be marked public and protected, but not private 3) Constructors can only have a primitive return type 4) Constructors are not inherited (Choose correct one from multiple below) 1. 1 and 2 2. 2 and 4 3. 1,3 and 4 4. 4 correct is :4 Explanations :Constructors can be marked public, private or protected. Constructors do not have a return type. -----------------------------------------------------------------------------Question No :114 What results from the following code? 1.class MyClass 2.{ 3.void myMethod(int i) {System.out.println("int version");} 4.void myMethod(String s) {System.out.println("String version");} 5.public static void main(String args[]) 6.{ 7.MyClass obj = new MyClass(); 8.char ch = 'c'; 9.obj.myMethod(ch); 10.} 11.} (Choose correct one from multiple below) 1. Line 4 will not compile as void methods can't be overridden. 2. An exception at line 9. 3. Line 9 will not compile as there is no version of myMethod which takes a char as argument. 4. The code compiles and produces output: int version. correct is :4 -----------------------------------------------------------------------------Question No :115 What will happen if you attempt to compile and run the following code? public class Test { public static void main(String argv[]){ Integer ten=new Integer(10); Long nine=new Long (9); System.out.println(ten + nine); int i=1; System.out.println(i + ten); } } (Choose correct one from multiple below) 1. 19 followed by 20 2. 19 followed by 11 3. Compile time error 4. 10 followed by 1 correct is :3 -----------------------------------------------------------------------------Question No :116 What will happen when you attempt to compile and run the following code with the command line "hello there" public class Arg{String[] MyArg; public static void main(String argv[]){ MyArg=argv; } public void amethod(){ System.out.println(argv[1]); } } (Choose correct one from multiple below) 1. Compile time error 2. Compilation and output of "hello" 3. Compilation and output of "there" 4. None of the above correct is :1 -----------------------------------------------------------------------------Question No :117 What will happen when you attempt to compile and run the following code class Base{ public void Base(){ System.out.println("Base"); } } public class In extends Base{ public static void main(String argv[]){ In i=new In(); } } (Choose correct one from multiple below) 1. Compile time error Base is a keyword 2. Compilation and no output at runtime 3. Output of Base 4. Runtime error Base has no valid constructor correct is :2 Explanations :Because the method in Base called Base has a return type it is not a constructor and there for does not get called on creation of an instance of its child class In -----------------------------------------------------------------------------Question No :118 class c1 { public static void main(String a[]) { System.out.println(Double.NaN==Double.NaN); System.out.println(Double.NaN!=Double.NaN); System.out.println(Float.NaN==Double.NaN); } } (Choose correct one from multiple below) 1. prints false true false 2. print true false true 3. prints true true true 4. prints false false false correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :119 When a byte is added to a char, what is the type of the result? (Choose correct one from multiple below) 1. byte 2. int 3. long 4. non of the above correct is :2 Explanations :The result of all arithmetic performed with the binary operators (not the assignment operators) is an int, a long, a float, or a double. Here byte and char are promoted to int, so the result is an int. -----------------------------------------------------------------------------Question No :120 Which of the following statements are true? 1) At the root of the collection hierarchy is a class called Collection 2) The collection interface contains a method called enumerator 3) The interator method returns an instance of the Vector class 4) The Set interface is designed for unique elements (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 4 correct is :4 -----------------------------------------------------------------------------Question No :121 What will happen when you attempt to compile and run this code? private class Base{} public class Vis{ transient int iVal; public static void main(String elephant[]){ } } (Choose correct one from multiple below) 1. Compile time error: Base cannot be private 2. Compile time error indicating that an integer cannot be transient 3. Compile time error transient not a data type 4. Compile time error malformed main method correct is :1 -----------------------------------------------------------------------------Question No :122 (Choose correct one from multiple below) 1. prints 34 2. prints 33 3. compile time error 4. Runtime exception correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :123 class A extends Thread { private int i; public void run() {i = 1;} public static void main(String[] args) { A a = new A(); a.run(); System.out.print(a.i); }} (Choose correct one from multiple below) 1. Prints nothing 2. Prints: 1 3. Prints: 01 4. Compile-time error correct is :2 Explanations :a.run() method was called instead of a.start(); so the full program runs as a single thread so a.run() is guaranteed to complete -----------------------------------------------------------------------------Question No :124 class C{ static int s; public static void main(String a[]){ C obj=new C(); obj.m1(); System.out.println(s); } void m1(); { int x=1; m2(x); System.out.println(x+""); } void m2(int x){ x=x*2; s=x; }} (Choose correct one from multiple below) 1. prints 1,2 2. prints 2,0 3. prints 2,2 4. compile time error correct is :1 Explanations :Only objects and arrays are passed by reference.other are passed by value.s is a static variable which is global to the class -----------------------------------------------------------------------------Question No :125 What happens if a class defines a method with the same name and parameters as a method in its superclass? (Choose correct one from multiple below) 1. The compiler automatically renames the subclass method. 2. The program runs since because overriding methods is allowed 3. The program throws a DuplicateMethod exception. 4. The compiler shows a DuplicateMethod error. correct is :2 -----------------------------------------------------------------------------Question No :126 What is the value of y? int y = 2 % 4; (Choose correct one from multiple below) 1. 0 2. 2 3. 4 4. Compile Error correct is :2 -----------------------------------------------------------------------------Question No :127 Which of the following statements about threading are true 1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable 2) You can obtain a mutually exclusive lock on any object 3) A thread can obtain a mutually exclusive lock on an object by calling a synchronized method on that object. 4) Thread scheduling algorithms are platform dependent (Choose correct one from multiple below) 1. 2,3,4 2. 1,2,3,4 3. 1,3 4. 3 correct is :1 -----------------------------------------------------------------------------Question No :128 How do you change the current layout manager for a container (Choose correct one from multiple below) 1. Use the setLayout method 2. Once created you cannot change the current layout manager of a component 3. Use the setLayoutManager method 4. Use the updateLayout method correct is :1 -----------------------------------------------------------------------------Question No :129 What will happen when you attempt to compile and run the following code? public class MyThread extends Thread { String myName; MyThread(String name) { myName = name; } public void run() { for(int i=0; i<100;i++) { System.out.println(myName); } } public static void main(String args[]) { try { MyThread mt1 = new MyThread("mt1"); MyThread mt2 = new MyThread("mt2"); mt1.start(); // XXX mt2.start(); } catch(InterruptedException ex) { } } } (Choose correct one from multiple below) 1. The above code in its current condition will not compile. 2. In order to make the MyThread class prints "mt1" (100 times) followed by "mt2" (100 times), mt1.join(); can be placed at //XXX position. 3. In order to make the MyThread class prints "mt1" (100 times) followed by "mt2" (100 times), mt1.sleep(100); can be placed at //XXX position. 4. In order to make the MyThread class prints "mt1" (100 times) followed by "mt2" (100 times), mt1.run(); can be placed at //XXX position. correct is :1 -----------------------------------------------------------------------------Question No :130 class C{ static String m(int i) {return "int";} static String m(float i) {return "float";} public static void main (String[] args) { long a1 = 1; double b1 = 2; System.out.print(m(a1)+","+ m(b1)); }} (Choose correct one from multiple below) 1. Prints: float,double 2. Prints: float,float 3. Prints: double,float 4. Compile-time error correct is :4 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :131 What will happen when you attempt to compile and run the following code? class MyThread extends Thread { public void run() { System.out.println("MyThread: run()"); } public void start() { System.out.println("MyThread: start()"); } } class MyRunnable implements Runnable { public void run() { System.out.println("MyRunnable: run()"); } public void start() { System.out.println("MyRunnable: start()"); } } public class MyTest { public static void main(String args[]) { MyThread myThread = new MyThread(); MyRunnable myRunnable = new MyRunnable(); Thread thread = new Thread(myRunnable); myThread.start(); thread.start(); } } (Choose correct one from multiple below) 1. Prints : MyThread: start() followed by MyRunnable:run() 2. Prints : MyThread: run() followed by MyRunnable:start() 3. Prints : MyThread: start() followed by MyRunnable:start() 4. Prints : MyThread: run() followed by MyRunnable:run() correct is :1 -----------------------------------------------------------------------------Question No :132 class C { public static void main (String[] a1) { System.out.print(a1[1] + a1[2] + a1[3]); }} java command A B C (Choose correct one from multiple below) 1. Prints: ABC 2. Prints BC and Runtime Exception 3. Prints: BCD 4. Runtime Exception correct is :2 Explanations :array index outof bounds exception only till a1[2] is allowed. -----------------------------------------------------------------------------Question No :133 class C { public static void main(String[] args) { int i1=1; switch(i1){ case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); }}} (Choose correct one from multiple below) 1. prints one two three 2. prints one 3. compile time error 4. Runtime exceptionf correct is :1 Explanations :There is no break statement in case 1 so it causes the below case statements to execute regardless of their values -----------------------------------------------------------------------------Question No :134 What will happen when you attempt to compile and run the following code? public class Inc{ public static void main(String argv[]){ Inc inc = new Inc(); int i =0; inc.fermin(i); i = i++; System.out.println(i); } void fermin(int i){ i++; } } (Choose correct one from multiple below) 1. Compile time error 2. Output of 2 3. Output of 1 4. Output of 0 correct is :4 Explanations :The method fermin only receives a copy of the variable i and any modifications to it are not reflected in the version in the calling method. The post increment operator ++ effectivly modifes the value of i after the initial value has been assiged to the left hand side of the equals operator. This can be a very tricky conept to understand -----------------------------------------------------------------------------Question No :135 Which statement is correct ? (Choose correct one from multiple below) 1. If super class has different constructor other then default then in the sub class you can use default constructor 2. If super class has different constructor other then default then in the sub class you can?t use default constructor 3. Both are true 4. none of the above correct is :2 -----------------------------------------------------------------------------Question No :136 What will happen when you attempt to compile and run the following code? interface MyInterface { } public class MyInstanceTest implements MyInterface { static String s; public static void main(String args[]) { MyInstanceTest t = new MyInstanceTest(); if(t instanceof MyInterface) { System.out.println("I am true interface"); } else { System.out.println("I am false interface"); } if(s instanceof String) { System.out.println("I am true String"); } else { System.out.println("I am false String"); } } } (Choose correct one from multiple below) 1. Prints : "I am true interface" followed by " I am true String" 2. Prints : "I am false interface" followed by " I am false String" 3. Prints : "I am true interface" followed by " I am false String" 4. Runtime error correct is :3 -----------------------------------------------------------------------------Question No :137 You need to read in the lines of a large text file containing tens of megabytes of data. Which of the following would be most suitable for reading in such a file 1) new FileInputStream("file.name") 2) new InputStreamReader(new FileInputStream("file.name")) 3) new BufferedReader(new InputStreamReader(new FileInputStream("file.name"))); 4) new RandomAccessFile raf=new RandomAccessFile("myfile.txt","+rw"); (Choose correct one from multiple below) 1. 1 and 3 2. 3 only 3. 1 and 2 4. none of the above correct is :2 -----------------------------------------------------------------------------Question No :138 What results from the following code? 1.class MyClass 2.{ 3.void myMethod(int i) {System.out.println("int version");} 4.void myMethod(String s) {System.out.println("String version");} 5.public static void main(String args[]) 6.{ 7.MyClass obj = new MyClass(); 8.char ch = 'c'; 9.obj.myMethod(ch); 10.} 11.} (Choose correct one from multiple below) 1. Line 4 will not compile as void methods can't be overridden. 2. An exception at line 9. 3. Line 9 will not compile as there is no version of myMethod which takes a char as argument. 4. The code compiles and produces output: int version. correct is :4 -----------------------------------------------------------------------------Question No :139 class A extends Thread { private int i; public void run() {i = 1;} public static void main(String[] args) { A a = new A(); a.run(); System.out.print(a.i); }} (Choose correct one from multiple below) 1. Prints nothing 2. Prints: 1 3. Prints: 01 4. Compile-time error correct is :2 Explanations :a.run() method was called instead of a.start(); so the full program runs as a single thread so a.run() is guaranteed to complete -----------------------------------------------------------------------------Question No :140 class A { B b = new B(); C c = (C) b; } Referring to the above, when is the cast of "b" to class C allowed? (Choose correct one from multiple below) 1. B and C are subclasses of the same superclass. 2. If B and C are superclasses of the same subclass 3. B is a subclass of C. 4. B is a superclass of C. correct is :3 -----------------------------------------------------------------------------Question No :141 class c1 extends Exception {} class c2 { static void m1() { throw new c1(); } public static void main(String a[]) { } } (Choose correct one from multiple below) 1. compile time error 2. Runtime Exception 3. The code compiles and runs fine 4. None of the above correct is :1 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :142 Which of the following lines will print false? 1.public class MyClass 2.{ 3.static String s1 = "I am unique!"; 4.public static void main(String args[]) 5.{ 6.String s2 = "I am unique!"; 7.String s3 = new String(s1); 8.System.out.println(s1 == s2); 9.System.out.println(s1.equals(s2)); 10.System.out.println(s3 == s1); 11.System.out.println(s3.equals(s1)); 12.System.out.println(TestClass.s4 == s1); 13.} 14.} 15. 16.class TestClass 17.{ 18.static String s4 = "I am unique!"; 19.} (Choose correct one from multiple below) 1. Lines 10 and 12 2. Line 12 only 3. Line 8 and 10 4. None of these correct is :4 -----------------------------------------------------------------------------Question No :143 interface I{ int i; // line 1 } class C implements I{ public static void main(String a[]){ System.out.println(i); System.out.println(i++); //line 2 } } (Choose correct one from multiple below) 1. compile time error at line 1,2 2. compile time error at line 2 3. Runtime exception 4. Noneofthe above correct is :1 Explanations :interface constants are final so,they must be initialized when declaring it and they can not be altered -----------------------------------------------------------------------------Question No :144 Given the following main method in a class called Cycle and a command line of java Cycle one two what will be output? public static void main(String bicycle[]){ System.out.println(bicycle[0]);} (Choose correct one from multiple below) 1. one 2. two 3. NULL 4. None correct is :1 -----------------------------------------------------------------------------Question No :145 Which of the following is not Java modifier? 1) public 2) private 3) friendly 4) transient (Choose correct one from multiple below) 1. 1 2. 2 3. 3 4. 4 correct is :3 -----------------------------------------------------------------------------Question No :146 Assuming any exception handling has been set up, which of the following will create an instance of the RandomAccessFile class (Choose correct one from multiple below) 1. RandomAccessFile raf=new RandomAccessFile("myfile.txt","rw"); 2. RandomAccessFile raf=new RandomAccessFile( new DataInputStream()); 3. RandomAccessFile raf=new RandomAccessFile("myfile.txt"); 4. RandomAccessFile raf=new RandomAccessFile( new File("myfile.txt")); correct is :1 Explanations :The RandomAccessFile is an anomaly in the Java I/O architecture. It descends directly from Object and is not part of the Streams architecture -----------------------------------------------------------------------------Question No :147 Q.You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use? (Choose correct one from multiple below) 1. myarray.length(); 2. myarray.length; 3. myarray.size 4. myarray.size(); correct is :2 -----------------------------------------------------------------------------Question No :148 public static double sin(double angle) What are the units of the "angle" argument? (Choose correct one from multiple below) 1. Degrees 2. Radians 3. Both 4. None of the above correct is :2 Explanations :No Explanation Available -----------------------------------------------------------------------------Question No :149 interface I { //1 public class Inner { ///2 Inner ( ) { System .out . println ( "Inner Created" ) ; } }; }; (Choose correct one from multiple below) 1. compile time error at line 1 2. compile time error at line 2 3. the code compiles fine 4. none of the above correct is :3 Explanations :No Explanation Available ------------------------------------------------------------------------------ Question No :150 class C { public static void main(String[] args) { char c1=65; switch(c1){ case 'A': System.out.println("one"); default: System.out.println("two"); case 'b': System.out.println("three"); }}} (Choose correct one from multiple below) 1. prints one twot hree 2. prints two three 3. compile time error 4. Runtime exception correct is :1 Explanations :char is a legal value for switch clause ------------------------------------------------------------------------------