Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java - Multiple Choice Questions (MCQ) - Introduction to Java - Set 2

6. What will be the output of the following Java program?

class increment 
    {
        public static void main(String args[])
        {
            double var1 = 1 + 5; 
            double var2 = var1 / 4;
            int var3 = 1 + 5;
            int var4 = var3 / 4;
            System.out.print(var2 + " " + var4);
 
        } 
    }
A). 1 1
B). 0 1
C). 1.5 1
D). 1.5 1.0
View Answer
Correct: C



7. What will be the output of the following Java program?

class Modulus 
    {
        public static void main(String args[]) 
        {    
             double a = 25.64;
             int  b = 25;
             a = a % 10;
             b = b % 10;
             System.out.println(a + " "  + b);
        } 
    }
A). 5.640000000000001 5
B). 5.640000000000001 5.0
C). 5 5
D). 5 5.640000000000001
View Answer
Correct: A



8. What will be the output of the following Java program?

    class increment 
    {
        public static void main(String args[]) 
        {        
             int g = 3;
             System.out.print(++g * 8);
        } 
    }
A). 25
B). 24
C). 32
D). 33
View Answer
Correct: C



9. Can 8 byte long data type be automatically type cast to 4 byte float data type?
A). TRUE
B). FALSE
View Answer
Correct: A



10. What will be the output of the following Java program?

    class Output 
    {
        public static void main(String args[]) 
        {    
             int a = 1;
             int b = 2;
             int c;
             int d;
             c = ++b;
             d = a++;
             c++;
             b++;
             ++a;
             System.out.println(a + " " + b + " " + c);
        } 
    }
A). 3 2 4
B). 3 2 3
C). 2 3 4
D). 3 4 4
View Answer
Correct: D



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper