ProgrammingHardInfosys DSE · Wipro Elite
What is printed?
What is printed?
class S {
static { System.out.print("s"); }
{ System.out.print("i"); }
S() { System.out.print("c"); }
}
// main: new S(); new S();- A. scici
- B. sicic
- C. sicsic
- D. iscic
Correct answer: B. sicic
The static block runs once at class initialization; each new object runs the instance initializer and then the constructor body.
More OOP with C++ and Java questions
- What does this print? java static StringBuilder f() { StringBuilder sb = new StringBuilder("a"); try { sb.append("b"); return sb; }…
- What is printed? java String a = "hi"; String b = new String("hi"); String c = b.intern(); System.out.print((a == b) + " " + (a == c) + "…
- What is printed? java static void f(Integer i) { System.out.print("I"); } static void f(long l) { System.out.print("L"); } static void…
- What is printed? java Integer a = 127, b = 127, c = 128, d = 128; System.out.print((a == b) + " " + (c == d) + " " + c.equals(d));
- What happens when this runs? java Integer n = null; boolean flag = false; Integer r = flag ? 1 : n; System.out.print(r);
- What is printed? java byte b = 10; b += 120; System.out.print(b + " " + (b >>> 1));