Thursday, April 9, 2020

Java Output questions set - 4


Set – 4

1.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 */
}

A. 9.0
B. bad number
C. Compilation fails on line 9.
D. Compilation fails on line 11.

2.class Q207
{
    public static void main(String[] args)
    {
        int i1 = 5;
        int i2 = 6;
        String s1 = "7";
        System.out.println(i1 + i2 + s1); /* Line 8 */
    }
}

A. 18
B. 117
C. 567
D. Compiler error

3.String a = "newspaper";
a = a.substring(5,7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);

A. apa
B. app
C. apea
D. apep

4.String d = "bookkeeper";
d.substring(1,7);
d = "w" + d;
d.append("woo");  /* Line 4 */
System.out.println(d);

A. wookkeewoo
B. wbookkeeper
C. wbookkeewoo
D. Compilation fails.

5.String a = "ABCD";
String b = a.toLowerCase();
b.replace('a','d');
b.replace('b','c');
System.out.println(b);

A. abcd
B. ABCD
C. dccd
D. dcba


6.class ForSample
{

    public static void main(String s[])
    {
        for(int i = 0; i <= 5; i++ )
        {
            System.out.println("i = " + i );
        }
    }
}


A.i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
B.i = 0
i = 1
i = 2
i = 3
i = 4
C.Compilation Errors
D.i = 1
i = 2
i = 3
i = 4

7.class Super {
    public int index = 1;
}

class App extends Super {

    public App(int index) {
        index = index;
    }

    public static void main(String args[]) {
        App myApp = new App(10);
        System.out.println(myApp.index);
    }
}
A. 0
B. 10
C. 1
D. Compile time error

8.class TestApp {
    protected int x, y;
}

class Main {
    public static void main(String args[]) {
        TestApp app = new TestApp();
        System.out.println(app.x + " " + app.y);
    }
}
A. 0 1
B. 1 0
C. 0 0
D. null null

9.class TestApp {
    public static void main(String[] args) {
        for (int index = 0; true; index++) {
            System.out.println("Welcome");
            break;
        }
    }
}
A. Welcome
B. None
C. Type mismatch error
D. Run infinite times

10.class TestApp {
    int i[] = { 0 };

    public static void main(String args[]) {
        int i[] = { 1 };
        alter(i);
        System.out.println(i[0]);
    }

    public static void alter(int i[]) {
        int j[] = { 2 };
        i = j;
    }
}
A. 0
B. 1
C. 2
D. Compilation error




No comments:

Post a Comment

Python Technical Interview Questions

 1)first non repeating character Malayalam y programming p str = "MalayalaM" a = '\0' for c in str:     if str.index(c) ==...