Object Oriented Programming - I (3140705) MCQs

MCQs of Introduction to java and elementary programming

Showing 81 to 90 out of 95 Questions
81.
What will be the output of the program?
class Test 
{
    public static void main(String [] args) 
    {
        int x=20;
        String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
        System.out.println(sup);
    }
}
(a) small
(b) tiny
(c) huge
(d) Compilation fails
Answer:

Option (b)

82.
What will be the output of the program?
class Test 
{
    public static void main(String [] args) 
    {
        int x= 0;
        int y= 0;
        for (int z = 0; z < 5; z++) 
        {
            if (( ++x > 2 ) || (++y > 2)) 
            {
                x++;
            }
        }
    System.out.println(x + " " + y);
    }
}
(a) 5 3
(b) 8 2
(c) 8 3
(d) 8 5
Answer:

Option (b)

83.
What will be the output of the program?
class Bitwise 
{
    public static void main(String [] args) 
    {
        int x = 11 & 9;
        int y = x ^ 3;
        System.out.println( y | 12 );
    }
}
(a) 0
(b) 7
(c) 8
(d) 14
Answer:

Option (d)

84.
Size of float and double in Java is
(a) 32 and 64
(b) 64 and 64
(c) 32 and 32
(d) 64 and 32
Answer:

Option (a)

85.
What would be the output of the following fraction of code ?
int Integer = 34 ;
char String = 'S' ;
System.out.print( Integer ) ;
System.out.print( String ) ;
(a) Does not compile as Integer and String are API class names.
(b) S
(c) 34
(d) 34 S
Answer:

Option (d)

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
Answer:

Option (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
Answer:

Option (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
Answer:

Option (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
Answer:

Option (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
Answer:

Option (c)

Showing 81 to 90 out of 95 Questions