Java Programming MCQ - Operators And Assignments

11. What will be the output of the program?

class Main {
    public static void main(String [] args)
   {
     Main p = new Main();
     p.start();
   }
   void start()
   {
    long [] a1 = {3,4,5};
    long [] a2 = fix(a1);
	System.out.print(a1[0] + a1[1] + a1[2] + " ");
	System.out.println(a2[0] + a2[1] + a2[2]);
   }
   long [] fix(long [] a3)
   {
	a3[1] = 7;
	return a3;
   }
}

A. 12 15
B. 15 15
C. 3 7 5 3 7 5
D. 3 4 5 3 7 5

View Answer


12. What will be the output of the program?

class Main {
    public static void main(String [] args)
	{
	 Main p = new Main();
	 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. true false
C. false true
D. false false

View Answer


13. What will be the output of the program?

class Main {
   public static void main(String [] args)
	{
	 Main p = new Main();
	 p.start();
	}
	void start()
	{
 	 String s1 = "s";
	 String s2 = fix(s1);
	 System.out.println(s1 + " " + s2);
	}
	String fix(String s1)
	{
	 s1 = s1 + "st";
	 System.out.print(s1 + " ");
	 return "st";
	}
}

A. s st
B. sst st
C. st s st
D. sst s st

View Answer


14. Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?

A. (int)Math.min(d);
B. (int)Math.abs(d);
C. (int)Math.max(d);
D. (int)Math.floor(d);

View Answer


15. Predict the output of following Java Program?

  
class Test {
	public static void main(String args[]) {
	 int x = -4;
	 System.out.println(x>>1);
	 int y = 4;
	 System.out.println(y>>1);
	}
}

A. Compiler Error: Operator >> cannot be applied to negative numbers
B. -2
2
C. 2
D. 2
2

View Answer


16. With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;

A. 1, 2 & 3
B. 1 & 4
C. 1, 2, 3 & 4
D. 3 & 2

View Answer


17. What is the output of this program?

class Main {
   public static void main(String args[])
	{
	 double var1 = 2 + 4;
	 double var2 = var1 / 4;
	 int var3 = 2 + 4;
	 int var4 = var3 / 4;
	 System.out.print(var2 + " " + var4);
	}
}

A. 0 1
B. 1 1
C. 1.5 1
D. 1.5 1.0

View Answer


18. What will be the output of the program?

class Main {
   public static void main(String [] args)
	{
	 int x=20;
	 String sup = (x < 15) ? "s" : (x < 22)? "t" : "h";
	 System.out.println(sup);
	}
}

A. s
B. t
C. h
D. Compilation fails

View Answer


19. 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. 7
B. 0
C. 14
D. 8

View Answer


20. What is the output of this program?

  
class increment
{
	public static void main(String args[])
	{
	 int g = 5;
	 System.out.print(++g * 8);
	}
}

A. 44
B. 56
C. 48
D. 40

View Answer






Also check :

Discussion


* You must be logged in to add comment.