You are on page 1of 18

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

Question 3 Given the code. What is the output?

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) 4 B) 5 C) 12 D) 11

Answer A

Question 4

Given the code. What is the result?

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

Given the code. What is the result?

public class Test1 { public static void main(String Args[]){ int i = 10;

while (++i <= 10) { i++; } System.out.print(i); } }

A) 10 B) 11 C) 12 D) Line 5 will be never reached.

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.

init() getServletInfo() service() getServletConfig() doGet()

Answer A,B,C,D

Question 9

Which one of these are true regarding inheritance in java?

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

Can we get servletContext Object by using servletConfig?

A) True B)False

Answer A

Question 11

What can directly access and change the value of the variable roomNr?

package com.mycompany; public class Hotel { public int roomNr = 100; }

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.

Requet Exception context in Out

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

What is the default method for HTTP request?

A)OPTIONS B)POST C)GET D)TRACE

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

Given the code. What is true (Choose the perfect answer)?

public class Test { enum State{ACTIVE, INACTIVE, DELETED}

A) Compilation Error B) Runtime Error C)Compilation will be successful D)Syntax Error

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

What is the ouput ?

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

Integer.parseInt("12a") returns A) Exception B) 1 C) 0 D) -1 Answer A

Question 21

Given the exhibit. What is the result?

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); } }

A) SHORT LONG B) short LONG C) Compilation fails D) An exception is thrown at runtime

Answer C

Question 22

Runnnable interface is a marker interface?

A) True B) False

Answer B

Question 23

What modifiers can be used with an interface declaration?

A. B. C. D.

protected abstract private public

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

How many finally{} blocks may there be in a try/catch structure?

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

Who implements Resultset Interface?

A. B. C. D.

JVM JDBC API Programmer Driver

Answer D

Question 27

How many implicit objects are there in JSP?

A)7 B)9 C)8 D)5

Answer B

Question 28

Given the code. What is the result if NullPointerException occurs at line 2?

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

You might also like