Object Oriented Programming - I (3140705) MCQs

MCQs of Methods and Arrays

Showing 1 to 10 out of 44 Questions
1.
When does method overloading is determined?
(a) At run time
(b) At compile time
(c) At coding time
(d) At execution time
Answer:

Option (b)

2.
When Overloading does not occur?
(a) More than one method with same name but different method signature and different number or type of parameters
(b) More than one method with same name, same signature but different number of signature
(c) More than one method with same name, same signature, same number of parameters but different type
(d) More than one method with same name, same number of parameters and type but different signature
Answer:

Option (d)

3.
What will be the output of the following Java code?
    class average {
        public static void main(String args[])
        {
            double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
            double result;
            result = 0;
            for (int i = 0; i < 6; ++i) 
                result = result + num[i];
	    System.out.print(result/6);
 
        } 
    }
(a) 16.34
(b) 16.566666644
(c) 16.46666666666667
(d) 16.46666666666666
Answer:

Option (c)

4.
What will be the output of the following Java program?
    class array_output {
        public static void main(String args[]) 
        {    
            char array_variable [] = new char[10];
	    for (int i = 0; i < 10; ++i) {
                array_variable[i] = 'i';
                System.out.print(array_variable[i] + "" );
                i++;
            }
        } 
    }
(a) i i i i i
(b) 0 1 2 3 4
(c) i j k l m
(d) None of the mentioned
Answer:

Option (a)

5.
What will be the output of the following Java 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
Answer:

Option (c)

6.
What will be the output of the following Java 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
Answer:

Option (b)

7.
What will be the output of the following Java program, if we run as “java main_arguments 1 2 3”?
    class main_arguments 
    {
        public static void main(String [] args) 
        {
            String [][] argument = new String[2][2];
            int x;
            argument[0] = args;
            x = argument[0].length;
            for (int y = 0; y < x; y++) 
                System.out.print(" " + argument[0][y]);              
        }
    }
(a) 1 1
(b) 1 0
(c) 1 0 3
(d) 1 2 3
Answer:

Option (d)

8.
Which will legally declare, construct, and initialize an array?
(a) int [] myList = {"1", "2", "3"};
(b) int [] myList = (5, 8, 2);
(c) int myList [] [] = {4,9,7,0};
(d) int myList [] = {4, 3, 7};
Answer:

Option (d)

9.
Which three are legal array declarations?
1. int [] myScores [];
2. char [] myChars;
3. int [6] myScores;
4. Dog myDogs [];
5. Dog myDogs [7];
(a) 1, 2, 4
(b) 2, 4, 5
(c) 2, 3, 4
(d) All are correct.
Answer:

Option (a)

10.
Which one of the following will declare an array and initialize it with five numbers?
(a) Array a = new Array(5);
(b) int [] a = {23,22,21,20,19};
(c) int a [] = new int[5];
(d) int [5] array;
Answer:

Option (b)

Showing 1 to 10 out of 44 Questions