Java Programming :: Operators and Assignments
-
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"; } }
-
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; } }
-
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; } }
-
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); } }
-
What will be the output of the program?
public class Test { public static void leftshift(int,int j) { i=j; } public static void main(String args[]) { int i = 4, j = 2; leftshift(i, j); System.out.println(i); } }