ProgrammingVery hardAccenture · GATE CS
What is printed?
What is printed?
Object o = true ? 1 : 2.0; System.out.print(o);
- A. 1
- B. 1.0
- C. true
- D. Compile error
Correct answer: B. 1.0
The two branches undergo binary numeric promotion to double, so the value is 1.0, not an Integer 1.
More OOP with C++ and Java questions
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct S { void f() { cout << "n"; } void f() const { cout << "c"; }…
- What does this Java method do when called? java static int f() { try { throw new RuntimeException("a"); } finally { return 5; } }
- What is printed? java String a = "ja" + "va"; String b = "java"; String c = "ja"; String d = c + "va"; System.out.print((a == b) + "," +…
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct A { A() { cout << "A"; } }; struct B : virtual A { }; struct…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { virtual void f(int x = 1) { cout <<…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { virtual void p() { cout << "A"; }…