Operators and Assignments Questions and Answers

Take Exam

In Java programming, Operators and Assignments form the backbone of logical and arithmetic operations. This concept frequently appears in programming questions and answers, particularly Java MCQs featured in company tests by TCS, Infosys, and Wipro. Java provides various operators—arithmetic, relational, logical, and bitwise—that allow developers to manipulate data and control program flow effectively. Understanding operator precedence, associativity, and assignment rules ensures accurate computations and reduces coding errors. Practicing Java programming interview questions with answers on operators and assignments helps students develop problem-solving skills necessary for coding challenges and technical interviews.

Operators and Assignments

Showing 10 of 38 questions

11. What will be the output of the program? class SC2 {     public static void main(String [] args)     {         SC2 s = new SC2();         s.start();     }     void start()     {         int a = 3;         int b = 4;         System.out.print(" " + 7 + 2 + " ");         System.out.print(a + b);         System.out.print(" " + a + b + " ");         System.out.print(foo() + a + b + " ");         System.out.println(a + b + foo());     }     String foo()     {         return "foo";     } }

  • 9 7 7 foo 7 7foo
  • 72 34 34 foo34 34foo
  • 9 7 7 foo34 34foo
  • 72 7 34 foo34 7foo
Show Answer Report

12. What will be the output of the program? class Test {     static int s;     public static void main(String [] args)     {         Test p = new Test();         p.start();         System.out.println(s);     }     void start()     {         int x = 7;         twice(x);         System.out.print(x + " ");     }     void twice(int x)     {         x = x*2;         s = x;     } }

  • 7 7
  • 7 14
  • 14 0
  • 14 14
Show Answer Report

13. What will be the output of the program? class Two {     byte x; } class PassO {     public static void main(String [] args)     {         PassO p = new PassO();         p.start();     }     void start()     {         Two t = new Two();         System.out.print(t.x + " ");         Two t2 = fix(t);         System.out.println(t.x + " " + t2.x);     }     Two fix(Two tt)     {         tt.x = 42;         return tt;     } }

  • null null 42
  • 0 0 42
  • 0 42 42
  • 0 0 0
Show Answer Report

14. What will be the output of the program? class BoolArray {     boolean [] b = new boolean[3];     int count = 0;     void set(boolean [] x, int i)     {         x[i] = true;         ++count;     }     public static void main(String [] args)     {         BoolArray ba = new BoolArray();         ba.set(ba.b, 0);         ba.set(ba.b, 2);         ba.test();     }     void test()     {         if ( b[0] && b[1] | b[2] )             count++;         if ( b[1] && b[(++count - 2)] )             count += 7;         System.out.println("count = " + count);     } }

  • count = 0
  • count = 2
  • count = 3
  • count = 4
Show Answer Report

15. What will be the output of the program? public class Test {     public static void leftshift(int i, int j)     {         i <<= j;     }     public static void main(String args[])     {         int i = 4, j = 2;         leftshift(i, j);         System.out.printIn(i);     } }

  • 2
  • 4
  • 8
  • 16
Show Answer Report

16. What is the output of int a = 5; a += 3 * 2;?

  • 11
  • 16
  • 13
  • 10
Show Answer Report

17. Which operator has the highest precedence?

  • +
  • ++
  • &&
  • =
Show Answer Report

18. What is the result of 10 / 3 in Java (integers)?

  • 3.3
  • 3
  • 4
  • 0
Show Answer Report

19. int x = 7; int y = ++x * 2; What is y?

  • 14
  • 16
  • 15
  • 12
Show Answer Report

20. What is the output of System.out.println(5 + 3 + "7");?

  • 57
  • 157
  • 87
  • 87.0
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test