Object Oriented Programming - I (3140705) MCQs

MCQs of Introduction to java and elementary programming

Showing 61 to 70 out of 95 Questions
61.
Which one is a valid declaration of a boolean?
(a) boolean b1 = 1;
(b) boolean b2 = ‘false’;
(c) boolean b3 = false;
(d) boolean b4 = ‘true’
Answer:

Option (c)

62.
What will be the output of the following Java program?
    class mainclass {
        public static void main(String args[]) 
        {
            char a = 'A';
            a++;
	    System.out.print((int)a);
        } 
    }
(a) 66
(b) 67
(c) 65
(d) 64
Answer:

Option (a)

63.
What will be the output of the following Java code?
    class asciicodes {
        public static void main(String args[]) 
        {
            char var1 = 'A';
	    char var2 = 'a';
	    System.out.println((int)var1 + " " + (int)var2);
        } 
    }
(a) 162
(b) 65 97
(c) 67 95
(d) 66 98
Answer:

Option (b)

64.
Which of these is long data type literal?
(a) 0x99fffL
(b) ABCDEFG
(c) 0x99fffa
(d) 99671246
Answer:

Option (a)

65.
Which of these can be returned by the operator &?
(a) Integer
(b) Boolean
(c) Character
(d) Integer or Boolean
Answer:

Option (d)

66.
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
Answer:

Option (b)

67.
What will be the output of the following Java program?
    class variable_scope 
    {
        public static void main(String args[]) 
        {
            int x;
            x = 5;
            {
	        int y = 6;
	        System.out.print(x + " " + y);
            }
            System.out.println(x + " " + y);
        } 
    }
(a) 5 6 5 6
(b) 5 6 5
(c) Runtime error
(d) Compilation error
Answer:

Option (d)

68.
Which of these is an incorrect string literal?
(a) “Hello World”
(b) “Hello\nWorld”
(c) “\”Hello World\””
(d) "Hello world"
Answer:

Option (d)

69.
Which of these is necessary condition for automatic type conversion in Java?
(a) The destination type is smaller than source type
(b) The destination type is larger than source type
(c) The destination type can be larger or smaller than source type
(d) None of the mentioned
Answer:

Option (b)

70.
What will be the error in the following Java code?
    byte b = 50;
    b = b * 50;
(a) b cannot contain value 100, limited by its range
(b) * operator has converted b * 50 into int, which can not be converted to byte without casting
(c) b cannot contain value 50
(d) No error in this code
Answer:

Option (b)

Showing 61 to 70 out of 95 Questions