Object Oriented Programming - I (3140705) MCQs

MCQs of Methods and Arrays

Showing 11 to 20 out of 44 Questions
11.
Which cause a compiler error?
(a) int[ ] scores = {3, 5, 7};
(b) int [ ][ ] scores = {2,7,6}, {9,3,45};
(c) String cats[ ] = {"Fluffy", "Spot", "Zeus"};
(d) boolean results[ ] = new boolean [] {true, false, true};
Answer:

Option (b)

12.
What is the widest valid returnType for methodA in line 3?
public class ReturnIt 
{ 
    returnType methodA(byte x, double y) /* Line 3 */
    { 
        return (long)x / y * 2; 
    } 
}
(a) int
(b) byte
(c) long
(d) double
Answer:

Option (d)

13.
Which one creates an instance of an array?
(a) int[ ] ia = new int[15];
(b) float fa = new float[20];
(c) char[ ] ca = "Some String";
(d) int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };
Answer:

Option (a)

14.
Which two cause a compiler error?
1. float[ ] f = new float(3);
2. float f2[ ] = new float[ ];
3. float[ ]f1 = new float[3];
4. float f3[ ] = new float[3];
5. float f5[ ] = {1.0f, 2.0f, 2.0f};
(a) 2, 4
(b) 3, 5
(c) 4, 5
(d) 1, 2
Answer:

Option (d)

15.
What will be the output of the program?
class Test 
{
    public static void main(String [] args) 
    {
        Test p = new Test();
        p.start();
    }

    void start() 
    {
        boolean b1 = false;
        boolean b2 = fix(b1);
        System.out.println(b1 + " " + b2);
    }

    boolean fix(boolean b1) 
    {
        b1 = true;
        return b1;
    }
}
(a) true true
(b) false true
(c) true false
(d) false false
Answer:

Option (b)

16.
Which of these operators is used to allocate memory to array variable in Java?
(a) malloc
(b) alloc
(c) new
(d) new malloc
Answer:

Option (c)

17.
What will be the output of the following Java code?
    int arr[] = new int [5];
    System.out.print(arr);
(a) 0
(b) value stored in arr[0]
(c) 00000
(d) Class name@ hashcode in hexadecimal form
Answer:

Option (d)

18.
Which of these is an incorrect Statement?
(a) It is necessary to use new operator to initialize an array
(b) Array can be initialized using comma separated expressions surrounded by curly braces
(c) Array can be initialized when they are declared
(d) None of the mentioned
Answer:

Option (a)

19.
Which of these is necessary to specify at time of array initialization?
(a) Row
(b) Column
(c) Both Row and Column
(d) None of the mentioned
Answer:

Option (a)

20.
What will be the output of the following Java code?
    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;
                System.out.print(array_variable[i] + " ");
                i++;
            }
        } 
    }
(a) 0 2 4 6 8
(b) 1 3 5 7 9
(c) 0 1 2 3 4 5 6 7 8 9
(d) 1 2 3 4 5 6 7 8 9 10
Answer:

Option (a)

Showing 11 to 20 out of 44 Questions