Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java MCQ - Introduction to Java - Set 18

86. What will be output of the following program code?

public class Test{
      public static void main(String[] a){
               short x = 10;
               x = x*5;
               System.out.print(x);
      }  
}
A). 50
B). 10
C). Compilation Error
D). None of these
View Answer
Correct: C



87. What will the output of the following program?

public class Test{
      public static void main(String args[]){
            float f = (1 / 4) * 10;
            int i = Math.round(f);
            System.out.println(i);
      }
}
A). 2
B). 0
C). 3
D). 2.5
View Answer
Correct: B



88. What will be output of following program?

public class Test{
      public static void main(String[] args){
            byte b=127;
            b++;
            b++;
            System.out.println(b);
      }
}
A). 2
B). 129
C). -127
D). Compiler error
View Answer
Correct: C



89. What is the output for the below code ?

public class A{
      static{
            System.out.println("static");
      }

      {
            System.out.println("block");
      }

      public A(){
            System.out.println("A");
      }

      public static void main(String[] args){
            A a = new A();
      }
}
A). A block static
B). static block A
C). static A
D). A
View Answer
Correct: B



90.

int x = 0, y = 0 , z = 0 ;
x = (++x + y-- ) * z++;
What will be the value of "x" after execution ?
A). -2
B). -1
C). 0
D). 1
View Answer
Correct: C



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper