Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java MCQ - Methods and Arrays - Set 30

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};
View Answer
Correct: 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
View Answer
Correct: 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 };
View Answer
Correct: 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
View Answer
Correct: 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
View Answer
Correct: B



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper