Tuesday, January 5, 2016

TT TEST -3 In JAVA / III CSE /2016

1.What is the output of the following code?

class Bitwise
{
    public static void main(String [] args)
    {
        int x = 11 & 9;
        int y = x ^ 3;
        System.out.println( y | 12 );
    }
}

2.What is the output of the following code?

public class Test

{

    public int aMethod()

    {

        static int i = 0;

        i++;

        return i;

    }

    public static void main(String args[])

    {

        Test test = new Test();

        test.aMethod();

        int j = test.aMethod();

        System.out.println(j);

    }

 }

3.What is the output of the following code?

int x = l, y = 6;

while (y--)

{

    x++;

}

System.out.println("x = " + x +" y = " + y);

4.What is the output of the following code?

for (int i = 0; i < 4; i += 2)

{

    System.out.print(i + " ");

}

System.out.println(i); /* Line 5 */

5.What is the output of the following code?

int x = 3;

int y = 1;

if (x = y) /* Line 3 */

{

    System.out.println("x =" + x);

}

6.What is the output of the following code?

try

{

    Float f1 = new Float("3.0");

    int x = f1.intValue();

    byte b = f1.byteValue();

    double d = f1.doubleValue();

    System.out.println(x + b + d);

}

catch (NumberFormatException e) /* Line 9 */

{

    System.out.println("bad number"); /* Line 11 */

}

7.What is the output of the following code?

class Super

{

    public int i = 0;

    public Super(String text) /* Line 4 */

    {

        i = 1;

    }

}

class Sub extends Super

{

    public Sub(String text)

    {

        i = 2;

    }

    public static void main(String args[])

    {

        Sub sub = new Sub("Hello");

        System.out.println(sub.i);

    }

}

8.What is the output of the following code?

class Base

{

    Base()

    {

        System.out.print("Base");

    }

}

public class Alpha extends Base

{

    public static void main(String[] args)

    {

        new Alpha(); /* Line 12 */

        new Base(); /* Line 13 */

    }

}

9.What is the output of the following code?

public class X

{

    public static void main(String [] args)

    {

        try

        {

            badMethod();

            System.out.print("A");

        }

        catch (Exception ex)

        {

            System.out.print("B");

        }

        finally

        {

            System.out.print("C");

        }

        System.out.print("D");

    }

    public static void badMethod()

    {

        throw new Error(); /* Line 22 */

    }

}

10.what is the missing code?

public class MyRunnable implements Runnable

{

    public void run()

    {

        // some code here

    }

}

11.What is the output of the following code?

public class While

{

    public void loop()

    {

        int x= 0;

        while ( 1 ) /* Line 6 */

        {

            System.out.print("x plus one is " + (x + 1)); /* Line 8 */

        }

    }

}

12.What is the output of the following code?

public class Test

{

    private static float[] f = new float[2];

    public static void main (String[] args)

    {

        System.out.println("f[0] = " + f[0]);

    }

}

13.What is the output of the following code?

class MyThread extends Thread

{

    public static void main(String [] args)

    {

        MyThread t = new MyThread(); /* Line 5 */

        t.run();  /* Line 6 */

    }

    public void run()

    {

        for(int i=1; i < 3; ++i)

        {

            System.out.print(i + "..");

        }

    }

}

14.What is the output of the following code?

class sam

{

    public static void main(String[] args)

    {

        int i1 = 5;

        int i2 = 6;

        String s1 = "7";

        System.out.println(i1 + i2 + s1); /* Line 8 */

    }

}

15.What is the output of the following code?

public class StringRef

{

    public static void main(String [] args)

    {

        String s1 = "abc";

        String s2 = "def";

        String s3 = s2;   /* Line 7 */

        s2 = "ghi";

        System.out.println(s1 + s2 + s3);

    }

}

          16. Demonstrate Applet.