Edifecs Technologies Technologie s
Java Technical Test – J2SE 5.0 SECTION I
1. Which of the following is not a keyword in Java? a.
goto
b. default c.
finalize
d. const e. package 2. Which one of the following declarations for an interface and class will compile? a.
interface A{} class B extends A{}
b. interface A{} class B implements A{} c.
interface A{} interface B implements A{}
d. interface A{} class B inherits A{} e. None of the above 3. Which of the following is a valid syntax for an e xpression in a JSP? a. <% 10 + 10 %> b. <%= 10 + 10 %> c.
<%! 10 + 10 %>
d. <%@ 10 + 10 %> e. <% (10 + 10); %> 4. What will be the output of the following code? class Test { public static void main(String… args) { String s1 = “abc”; String s2 = “abc”; String s3 = new String(“abc”); System.out.print(s1 System.out.prin t(s1 == s2); System.out.print(“ System.out.prin t(“ “ + (s1 == s3)); System.out.print(“ System.out.prin t(“ “ + (s2.equals(s3))); } }
a. false false true b. false true true c.
false true true
d. true false true e. true true true 5. Objects in Java are created on ______________ (Choose one). a. Heap b. Stack
Page 1
Edifecs Technologies c.
Java Technical Test – J2SE 5.0
Register
d. ROM e. None of the above 6. Which one of the following statements is true about constructors? a. Constructors must not have arguments if super class does not have arguments in its constructors b. Constructors cannot be overloaded c.
Constructors cannot be marked as public
d. The first statement of every constructor is a call to super() or this() e. Constructors can be explicitly called by the programmer using a reference to an object 7. Given a method in a class, what access modifier will you use to restrict access to that method to only the other members of the same class? a. final b. static c.
public
d. default e. private 8. Which of the following are methods of t he Servlet Life Cycle? a. init, service, destroy b. initialize, service, destroy c.
init, execute, finalize
d. init, execute, destroy e. initialize, execute, destroy 9. Which concept of OOPs is realized in the following piece of code? class Alpha { } class Beta extends Alpha { }
a. Encapsulation b. Cohesion c.
Polymorphism
d. Inheritance e. Abstraction 10. Which one of following is correct? a. <% static int j = 0; %> b. <% public void m1() {} %> c.
<%! static int k = 0; %>
d. <% println(50 + 50); %> e. <%! System.out.println(“inside declaration”); %>
Page 2
Edifecs Technologies
Java Technical Test – J2SE 5.0 SECTION II
1. Which of the following is a valid way to access ‘InnerClass’ defined from the main method? class OuterClass { class InnerClass {} } class TestInnerClass { public static void main(String [] args) { /* Code goes here */ } } a. InnerClass inner = new InnerClass(); b. OuterClass.InnerClass inner = new OuterClass.InnerClass(); c.
InnerClass inner = new OuterClass.InnerClass();
d. InnerClass inner = new InnerClass.instance(); e. OuterClass.InnerClass inner = new OuterClass().new InnerClass(); 2. Which collection class can provide indexed access to its elements while maintaining variable length of itself, but whose methods are not synchronized? (Choose One) a. java.util.TreeSet b. java.util.Vector c. java.util.HashSet d. java.util.PriorityQueue e. java.util.ArrayList 3. Which method in doGet in an HttpServlet configured at the provided URL, will ret rieve the value of the field in the form below?
a. request.getParameter(“fullName”); b. request.getParameter(“name”); c.
request.getAttribute(“fullName”);
d. response.getAttribute(“name”); e. response.getParameter(“name”); 4. Which of the following will compile correctly? (Choose two) a. char ch = ‘\u0010’; b. char ch = “c”; c.
int i = ‘a’;
d. float f = 9.5; e. long l = 99999999999;
Page 3
Edifecs Technologies
Java Technical Test – J2SE 5.0
5. What will be the output of the following code snippet in a JSP? <%! String abc = “Hello World” %> <% String abc = “Hi World” %> <%= abc %> a. Hello World b. Hi World c.
Hello World HI World
d. Compilation fails e. Translation fails 6. Which of the following is a valid taglib directive? a. <%@ taglib uri=”http://abc.web.com” suffix=”tld” %> b. <% taglib url=”http://abc.web.com” suffix=”tld” %> c.
<% taglib url=”http://abc.web.com” prefix=”tld” %>
d. <%@ taglib prefix=”tld” tagurl=”http://abc.web.com” %> e. <%@ taglib prefix=”tld” uri=”http://abc.web.com” %> 7. Which of the following are correct ways to declare an array? (Choose all that are correct) a. int [][] a = new int[2][3]; b. int []a[] = new int[3][]; c.
int a[1][2];
d. int a[][] = {{1, 2, 3}, {3, 4, 5}}; e. int [1][2]a = new int[1][2]; 8. Which of the following three statements are true? a. A final method in class X can be abstract if and only if X is abstract b. A protected method in class X can be overridden by any subclass of X c.
A private static method of class X can be called only from other static methods of class X
d. A method with the same signature as a private final method in class X c an be implemented in subclass of X. e. A protected method of class X can be overridden by its subclass as a public method. 9. What will be the output of the following code? class Alpha { public Object getObject() { return new Object() { public String toString() { return “Object Object”; } }; } } class Beta extends Alpha {
Page 4
Edifecs Technologies
Java Technical Test – J2SE 5.0
public String getObject() { return new String(“String Object”); } } class Main { public static void main(String [] args) { Alpha alpha = new Beta(); System.out.println(alpha.getObject()); } }
a. Compilation fails b. Exception is thrown at runtime c.
Object Object
d. String Object e. Compiles fine and runs with no output 10. What is the function of the encodeURL method of the HttpServletRequest interface? a. It encodes the url to replace special characters by their equivalent ASCII codes b. It rewrites the url to replace only the white spaces in a url c.
It encodes the url to include a request parameter that contains cookies
d. It rewrites url to include session ID of the current session e. None of the above 11. Which of the following is a correct summary of the MVC design pattern? a. MVC design pattern stands for Model View and Controller where the model is typically a POJO (Plain old java object), the controller can be a servlet or a java class and the views are formed mostly by JSPs b. MVC design pattern stands for Model Version and Class where the model is the Java framework used in the application, version is the version of Java used and Class is the controller for the application c.
MVC design pattern stands for Mode, Version and Class where the mode is the mode in which Java operates like remote or stand alone, version is the version of Java used and class is the controller for the application
d. MVC design pattern stands for Model Version and Controller where the model is typically a POJO, the version is the version of Java used and controller is the xml file which contains the application settings that are read by the container e. MVC design pattern stands for Mode View and Controller where the mode re presents the operational states of the objects, the views are represented by Java objects and Controller is the xml file read by the server which contains application settings
Page 5
Edifecs Technologies
Java Technical Test – J2SE 5.0 SECTION III
1. What will be the output of the following code? class Main { enum Colors { RED(“Rose”), YELLOW(“Sunflower”), WHITE; private String color; Colors(String color) { this.color = color; } Colors() {} public String toString() { return this.color; } } public static void main(String [] args) { Colors color = Colors.WHITE; switch (color) { case WHITE: System.out.println(color); case RED: System.out.println(Colors.RED); case YELLOW: System.out.println(Colors.Yellow); } } } a. WHITE b. WHITE RED YELLOW c.
null Rose Sunflower
d. Compilation fails e. WHITE Rose Sunflower 2. Which of the following statements is true for the code given below? class TestThread extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run(){ doThings(); } }
Page 6
Edifecs Technologies
Java Technical Test – J2SE 5.0
a. An exception is thrown at runtime b. Synchronizing the run() method would make the class thread-safe c.
The data variable ‘x’ is protecte d from any concurrent access problems
d. Wrapping the statements within the doThings() method in a synchronized(new TestThread()) {} block will make the data variable ‘x’ thread safe e. Declaring the doThings() method as static would make the class thread-safe 3. Will the following code compile? interface Foo { void fooMethod(); } abstract class Bar implements Foo { abstract void fooMethod(); } class FooBar extends Bar implements Foo { public void fooMethod() {} } a. Compilation fails because of an error in Foo b. Compilation fails because of an error in Bar c.
Compilation fails because of an error in FooBar
d. Compilation succeeds e. Compilation will succeed if public keyword is removed from declaration of fooMethod in FooBar 4. Which line/s of code can replace the comments in the code block below? (Choose two) class Animal {} class Dog extends Animal{} class Cat extends Animal{} class Zoo { public static void main(String [] args) { /*code segment here*/ countAnimals(animals); } public static void countAnimals(/*code here*/ animals) { System.out.println(animals.size()); } } a. List
animals = new ArrayList(); List b. List animals = new ArrayList(); List extends Dog> c.
List extends Animal> animals = new ArrayList(); List extends Animal>
d. List animals = new ArrayList(); List super Dog> e. List(); List super Cat>
Page 7