Sie sind auf Seite 1von 10

Section I: Technical Ability

(Q. No. 1-10) 1) What is the output of the following program? public class TestClass {

public static void main(String args[]){

A a1 = new A(); A a2 = new B(); B b2 = new B(); } }

class A{ public A(){ System.out.println("I AM FROM A"); } public void print(){ System.out.println("I AM IN FUNCTION A"); } }

class B extends A{ public B(){ System.out.println("I AM FROM B"); } public void print(){ System.out.println("I AM IN FUNCTION B");

} }

I AM FROM A I AM FROM A I AM FROM B I AM FROM A I AM FROM B

Options: A) it does not compile . B) It prints the following on the console I AM FROM A I AM FROM A I AM FROM B I AM FROM A I AM FROM B

C) It prints the Following on the console I AM FROM A I AM FROM A I AM FROM B

D) It prints the Following on the console I AM FROM A I AM FROM B I AM FROM A

I AM FROM B I AM FROM A -----------------------------------------

2) What is the output of the following program?

class A{ publicint x =10; }

class B extends A{ publicint x =20; } public class TestClass { public static void main(String args[]){ B a1 =new B(); A a2 =new B(); System.out.println("a1 == "+a1.x ); // (1) System.out.println("a2 == "+a2.x ); // (2) } }

a1 == 20 a2 == 10 Options: A) a1 == 10 a2 == 10 B) a1 == 10 a2 == 20 C) a1 == 20 a2 == 20 D) a1 == 20

a2 == 10 ------------------------------------3) What happens when this code gets compiled and executed?

public class Run { public static void main(String[] args) { System.out.print("A "); synchronized (new Object()) { new Object().notifyAll(); } System.out.println("B"); } }

1. It prints A B. 2. Compilation fails. 3. It prints A and an exception is thrown. 4. None of the above. ---------------------------------------4) The result of evaluating prefix expression */b+-dacd, where a = 3, b = 6, c = 1, d = 5 is

a. 8 b. 14 c. 10 d. 3 -------------------------------------

5) What is the correct answer for the following program?

package p1;

class A { protectedint x = 10; int y = 20;

package p1; class B{ public void print(){ A a1 = new A(); System.out.println("X = "+ a1.x ); // (1) System.out.println("Y = "+ a1.y ); // (2) } }

package p2; import p1; class C extends A{

public void print(){ System.out.println("X = "+ this.x ); //(3) System.out.println("Y = "+ this.y ); //(4) } }

Options A) Compilation error at (1) B) Compilation error at (1) and (2) C) Compilation error at (1) and (4) D) Compilation error at (4) -------------------------------------

6) When inorder traversing a tree resulted E A C K F H D B G; the preorder traversal would return

a. FAEKCDBHG b. FAEKCDHGB c. EAFKHDCBG d. FEAKDCHBG -------------------------------------

7) Binary search algorithm cannot be applied to a. sorted linked list b. sorted binary trees c. sorted linear array d. pointer array -------------------------------------

8) These classes are defined in the same file. What is the output?

class Job extends Thread { private Integer number = 0;

public void run() { synchronized (this) { for (int i = 1; i < 1000000; i++) { number++; } notify(); } } public Integer getNumber() { return number; } }

public class Test { public static void main(String[] args) throws Exception { Job thread = new Job(); thread.start(); synchronized (thread) { thread.wait(); } System.out.println(thread.getNumber()); } } Options a) b) c) d) It prints 0 It prints 999999 The output is not guaranteed to be any of the above It prints -999999

-----------------------------------------------

8) Given a Class B Network with subnet mask of 255.255.248.0 and a packet addressed to 130.40.32.16, what is the subnet address?

a) b) c) d)

130.40.32.0 130.40.32.7 130.39.32.0 130.39.32.7

----------------------------------------------10) Consider the following classes.

public class Team implements Serializable { Coach coach = new Coach(); Player[] players = new Player[5];

public Team() { players[0] = new Player(); players[1] = new Player(); players[2] = new Player(); players[3] = new Player(); players[4] = new Player(); } } public class Coach implements Serializable {

public class Player { } What happens when an object of Team gets serialized?

1. A NotSerializableException is thrown at runtime, because Player does not implement Serializable. 2. A NotSerializableException is thrown at runtime, because arrays cannot get serialized. 3. Serialization succeeds, but the array of players does not get serialized. 4. Serialization succeeds, including the array of players.

Das könnte Ihnen auch gefallen