ProgrammingHardTCS NQT Prime · Infosys SP
What is printed?
What is printed?
outer:
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (j == 1) continue outer;
if (i == 2) break outer;
System.out.print(i + "" + j + ",");
}
}- A. 00,10,
- B. 00,01,10,
- C. 00,10,20,
- D. 00,01,02,10,11,12,
Correct answer: A. 00,10,
Each i prints only j=0 because j==1 continues the outer loop; at i=2, j=0 triggers break outer before printing.
More OOP with C++ and Java questions
- What is printed? java class A { static final int X = 5; static final Integer Y = 6; static { System.out.print("A"); } } // main…
- What is printed? java class A { private void f() { System.out.print("A"); } void g() { f(); } } class B extends A { void f() {…
- What is printed? java class A { void f() { System.out.print("A"); g(); } void g() { System.out.print("a"); } } class B extends A { void…
- What is printed? java int x = Integer.MAXVALUE; long y = x + 1; long z = x + 1L; System.out.print(y + " " + z);
- What is printed? java class A { A() { this(1); System.out.print("0"); } A(int x) { System.out.print("1"); } } class B extends A { B() {…
- Which OOP principle bundles data with the methods that act on it and hides the internal state behind an interface?