Literals & Variables

1

What is the output of this program?

    class dynamic_initialization {
        public static void main(String args[]) 
        {
            double a, b;
            a = 3.0;
            b = 4.0;
	    double c = Math.sqrt(a * a + b * b);
	    System.out.println(c);
        } 
    }
A. 5.0
B. 25.0
C. 7.0
D. Compilation Error

2

Which of these is incorrect string literal?
A. "Hello World"
B. "Hello`setminus`nWorld"
C. "`setminus`"Hello World`setminus`""
D. "Hello
world"


3

What is the output of this program?

    class array_output {
        public static void main(String args[]) 
        {
       	    int array_variable [] = new int[10];
	    for (int i = 0; i < 10; ++i) {
                array_variable[i] = i/2;
                array_variable[i]++;
                System.out.print(array_variable[i] + " ");
                i++;
            }
 
        } 
    }
A. 0 2 4 6 8
B. 1 2 3 4 5
C. 0 1 2 3 4 5 6 7 8 9
D. 1 2 3 4 5 6 7 8 9 10

4

What is the output of this program?

    class evaluate {
        public static void main(String args[]) 
        {
            int a[] = {1,2,3,4,5};
	    int d[] = a;
	    int sum = 0;
	    for (int j = 0; j < 3; ++j)
                sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
	    System.out.println(sum);
        } 
    }
A. 38
B. 39
C. 40
D. 41

5

Which of these can not be used for a variable name in Java?

A. identifier
B. keyword
C. identifier & keyword
D. None of the mentioned