Question 1
Question 1
Question 1
public classCruiser implements Runnable { public static void main(String[] args) { Thread a = new Thread(new Cruiser()); a.start(); System.out.print("Begin"); a.join(); System.out.print("End"); } public void run() { System.out.print("Run"); } }
A) Compilation fails. B) An exception is thrown at runtime. C) "BeginRunEnd" is printed. D) "BeginEndRun" is printed. E) "BeginEnd" is printed.
Answer A
Question 2
public static void main(String args[]) { Object myObj = new String[]{"one", "two", "three"};{ for (String s : (String[])myObj) System.out.print(s + "."); } }
A) one.two.three. B) Compilation fails because of an error at line 2 C) Compilation fails because of an error at line 3 D) An exception is thrown at runtime.
Answer A
A) 4 B) 5 C) 12 D) 11
Answer A
Question 4
import java.util.HashSet; public class HashTest { private String str; public HashTest(String str) { this.str = str; } public static void main(String args[]) { HashTest h1 = new HashTest("1"); HashTest h2 = new HashTest("1");
String s1 = new String("2"); String s2 = new String("2"); HashSet<Object> hs = new HashSet<Object>(); hs.add(h1); hs.add(h2); hs.add(s1); hs.add(s2); System.out.print(hs.size()); } }
A) "4" is printed. B) "3" is printed C) "2" is printed. D) Compilation fails. E) An exception is thrown at runtime.
Answer B
Question 5
public class Test1 { public static void main(String Args[]){ int i = 10;
Answer B
Question 6
public class Test { int a = 10; public void doStuff(int a) { a += 1; System.out.println(a++); } public static void main(String args[]) { Test t = new Test(); t.doStuff(3); } }
A) 11 B) 12 C) 4 D) 5
Answer D
Question 7
The root of the deployment descriptor is named as A)web B)web-app C)name D)display-name
Answer B
Question 8
Which of the below methods belong to javax.servlet.Servlet interface:(Choose all that applies):
A. B. C. D. E.
Answer A,B,C,D
Question 9
A. B. C. D.
A class can implement multiple interfaces An interface can extend single interfaces A class can implement single interfaces An interface can extend multiple interfaces
Answer A,D
Question 10
A) True B)False
Answer A
Question 11
What can directly access and change the value of the variable roomNr?
A) Only the Hotel class. B) Any class. C) Any class in com.mycompany package. D) Any class that extends Hotel.
Answer B
Question 12
Which of the below are JSP implicit Objects(Choose all that applies):
A. B. C. D. E.
Answer A,B,E
Question 13
Which of these are true. A. The default value of isThreadSafe attribute of page directive is true. B. If isThreadSafe attribute of page directive is set to true, then JSP container dispatches request for the page sequentially. C. When isThreadSafe attribute of page directive is set to true, a thread is created for each request for the page. D. Setting isThreadSage attribute to false causes the JSP page implementation class to implement the SingleThreadModel interface Answers A,C,D
Question 14
Answer : C
Question 16
Once a Servlet is initialized, how do you get the initialization parameters ? A. B. C. D. Initialization parameters will not be stored They will be stored in instance variable using config.getInitParameters() By Calling doinit() method
Answer C
Question 17
Answer C
Question 18
We can override all the life cycle methods of JSP (jspInit(), jspService(),jspDestroy()) method?
A)True B)False
Answer B
Question 19
public Test { public static void main(String args[]){ String test = "This is a test string"; String[] tokens = test.split("\\s"); System.out.println(tokens.length); } } A) 0 B) 5 C)21 D)Compilation fails
Answer - B
Question 20
Question 21
public class Hotel { public static void book(short a) { System.out.print("short "); } public static void book(Short a) { System.out.print("SHORT "); } public static void book(Long a) { System.out.print("LONG "); } public static void main(String[] args) { short shortRoom = 1; int intRoom = 2; book(shortRoom); book(intRoom); } }
Answer C
Question 22
A) True B) False
Answer B
Question 23
A. B. C. D.
Answer B,D
Question 24
What is true? Difference Between Interface and Abstract class? A. B. C. D. both are same abstract class has only method signature interface has only method signature none of the above
Answer C
Question 25
A. B. C. D.
There must always be one, following the last catch{} block. There can be zero or one immediately after each catch{} block. There can be zero or one, following the last catch{} block. There can be any number, following the last catch{} block.
Answer C
Question 26
A. B. C. D.
Answer D
Question 27
Answer B
Question 28
1. try { 2. //some code goes here 3. } 4. catch (NullPointerException ne) { 5. System.out.print("1 "); 6. } 7. catch (RuntimeException re) { 8. System.out.print("2 "); 9. } 10. finally { 11. System.out.print("3"); 12. } A)1 B)1 2 C)2 3 D)1 3
Answer D
Question 29
What is true (Choose all that apply) :What is the difference between JSP Action include and Directive include?
A) Action type include is a compile time inclusion B)JSP Action tag will be included during run time C)Directive include will be part of translation phase D) All the above
E)B,C
Answer E
Question 30
Runtime Exceptions are: A. Checked Exceptions B. Unchecked Exceptions C. Custom Exceptions D. Illegal Exceptions Answer B