AMITI PAPER- APR 2007-BANGLORE

I wrote the online test. 25 questions were there. But I couldn’t retrieve all the questions. Also I don’t know the answers. Sorry. But all are the questions related to codings,output…Not normal one word answer objective type..So be prepare for that.

With Rgds
Ambika

[b][size=3]Amiti Software[/size][/b]

1) class Parent
{
private void method1()
{
System.out.println(”Parent’s method1());”
}

public void method2()
{
System.out.println(”Parent’s method2());”
method1();
}
}

class Child extends Parent
{
public void method1()
{
System.out.println(”Child’s method1());”
}

public static void main(String args[])

{
Parent p = new Child();
p.method2();
}

}

2) #1 Given:
1. public abstract class Prod {
2. public abstract void prmth1();
3. public static void prmth2() {
4. int mth2 = 30;
5. System.out.println(”prmth2 = ” + mth2);
6. } http://www.ChetanaS.org
7. public abstract void prmth3();
8. }
What is the result?

Compilation succeeds
Compilation fails because of an error on line 1
Compilation fails because of an error on line 3
Compilation fails because of an error on line 7

3)What will happen if you attempt to compile and run the following code?

class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx
{
public static void main(String argv[])
{
Base b=new Base();
Sub s=(Sub) b;
}
}

Compile and run without error
Compile time Exception
Runtime Exception

4)Which of the following statements are true?
a) System.out.println( -1 >>> 2 );will output a result larger than 10
b)System.out.println( -1 >>> 2); will output a positive number
c)System.out.println( 2 >> 1 );will output the number 1
d)System.out.println( 1 <<< 2 );will output the number 4

5)What is the value of z?
double z = 7 / (3 + 0.5)
a) 0.5 B)2.0 c) 2.83333333 d) 3.0

6) What results from attempting to compile and run the following code?
public class Ternary
{
public static void main(String args[])
{
int a = 5;
System.out.println(”Value is - ” + ((a < 5) ? 9.9 : 9)
}
}
a)Prints: Value is - 9 b)Prints: Value is - 5 c)Compilation error d)Value is - 9.0

7)Consider the class hierarchy shown below:
————————————————
class FourWheeler implements DrivingUtilities
class Car extends FourWheeler
class Truck extends FourWheeler
class Bus extends FourWheeler
class Crane extends FourWheeler
————————————————

Consider the following code below:
1. DrivingUtilities du;
2. FourWheeler fw;
3. Truck myTruck = new Truck();
4. du = (DrivingUtilities)myTruck;
5. fw = new Crane();
6. fw = du;
Which of the statements below are true?

a) Line 4 will not compile because an interface cannot refer to an object.
b)The code will compile and run. Ch etan aS
c) The code will not compile without an explicit cast at line 6, because going down the hierarchy without casting is not allowed.
d) The code at line 4 will compile even without the explicit cast.
e) The code will compile if we put an explicit cast at line 6 but will throw an exception at runtime.

8) What will happen when you attempt to compile and run the following code snippet?

Boolean b = new Boolean(”TRUE”);
if(b.booleanValue())
{
System.out.println(”Yes : ” +B);
}
else
{
System.out.println(”No : ” +B);
}

a) The code will not compile.
b) It will print - Yes : true
c) It will print - Yes : TRUE
d) It will print - No : false
e) It will print - No : FALSE

9) What will happen when you attempt to compile and run the following code?

public class Tux extends Thread
{
static String sName = “vandeleur”;
public static void main(String argv[])
{
Tux t = new Tux();
t.piggy(sName);
System.out.println(sName)
}
public void piggy(String sName)
{
sName = sName + ” wiggy”;
start();
}
public void run()
{
for(int i=0;i < 4; i++)
{
sName = sName + ” ” + i;
}
}
}

a) Compile time error
b) Compilation and output of “vandeleur wiggy”
c) Compilation and output of “vandeleur wiggy 0 1 2 3″
d) Compilation and output of either “vandeleur”, “vandeleur 0″, “vandeleur 0 1″ “vandaleur 0 1 2″ or “vandaleur 0 1 2 3″

10) What will be output by the following code?

public class MyFor
{
public static void main(String argv[])
{
int i;
int j;
outer:
for (i=1;i <3;i++){
inner:
for(j=1; j<3; j++)
{
if (j== 2)
continue outer;
System.out.println(”Value for i=” + i + ” Value for j=” +j);
}
}
}

a) Value for i=1 Value for j=1
b) Value for i=2 Value for j=1
c) Value for i=2 Value for j=2
d) Value for i=3 Value for j=1

11) What will happen when you attempt to compile and run the following code?

public class Holt extends Thread
{
private String sThreadName;
public static void main(String argv[])
{
Holt h = new Holt();
h.go();
}

Holt(){}
Holt(String s)
{
sThreadName = s;
}

public String getThreadName()
{
return sThreadName;
}

public void go()
{
Holt first = new Holt(”first”)
first.start();
Holt second = new Holt(”second”)
second.start();
}

public void start()
{
for(int i = 0; i < 2; i ++)
{
System.out.println(getThreadName() +i
try
{
Thread.sleep(100);
}
catch(InterruptedException e)
{
System.out.println(e.getMessage());
}
}
}
}

a) Compile time error
b) Output of first0, second0, first0, second1
c) Output of first0, first1, second0, second1
d) Runtime error

12) Given the following code how could you invoke the Base constructor that will print out the string “base constructor”;
class Base
{
Base(int i)
{
System.out.println(”base constructor”);
}
Base()
{ }

}

public class Sup extends Base
{
public static void main(String argv[])
{
Sup s= new Sup();
//One
}
Sup()
{
//Two
}
public void derived()
{
//Three
}

}

a) On the line After //One put Base(10);
b) On the line After //One put super(10);
c) On the line After //Two put super(10);
d) On the line After //Three put super(10);

13) What will happen when you attempt to compile and run the following code?

class Base
{
private void amethod(int iBase)
{
System.out.println(”Base.amethod”);
}
}

class Over extends Base
{
public static void main(String argv[])
{
Over o = new Over();
int iBase=0;
o.amethod(iBase);
}

public void amethod(int iOver)
{
System.out.println(”Over.amethod”);
}

}

a) Compile time error complaining that Base.amethod is private
b) Runtime error complaining that Base.amethod is private
c) Output of “Base.amethod”
d) Output of “Over.amethod”

14) Consider these classes, defined in separate source files:
1. public class Test1 {
2. public float aMethod(float a, float b)throws IOException {
3. }
4. }

1. public class Test2 extends Test1 {
2.
3. }

Which of the following methods would be legal (individually) at line 2 in class Test2?

a) float aMethod(float a, float B){ }
b) public int aMethod(int a, int b)throws Exception { }
c) public float aMethod(float a, float b)throws Exception { }
d) public float aMethod(float p, float q) RuntimeException{ }

15) Consider the following classes, declared in separate source files:
1. public class Base {
2. public void method(int i) {
3. System.out.println(”Value is ” + i);
4. }
5. }

1. public class Sub extends Base {
2. public void method(int j) {
3. System.out.println(”This value is ” + j);
4. }
5. public void method(String s) {
6. System.out.println(”I was passed ” + s);
7. }
8. public static void main(String args[]) {
9. Base b1 = new Base();
10. Base b2 = new Sub();
11. b1.method(5);
12. b2.method(6);
13. }
14. }

What output results when the main method of the class Sub is run?
a) Value is 5
Value is 6
b)This value is 5
This value is 6
c) Value is 5
This value is 6
d) This value is 5
Value is 6
e) I was passed 5
I was passed 6

Chandu-MCA
Hyderabad

Leave a Reply

You must be logged in to post a comment.

Close