ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
char x = 'A';
int i = 0;
System.out.print(true ? 1 : 2.0);
System.out.print(" ");
System.out.print(true ? x : i);- A. 1.0 A
- B. 1 A
- C. 1.0 65
- D. 1 65
Correct answer: C. 1.0 65
The two branches of ?: are brought to one type. int and double give double, so 1 prints as 1.0. char and an int variable give int, so 'A' prints as 65 (only an int constant that fits in char would keep the type char).
More OOP with C++ and Java questions
- What is printed? cpp struct B { void f(int) { cout << "Bi"; } void f(double) { cout << "Bd"; } }; struct D : B { void f(double) { cout <<…
- How many of these are correct about C++ virtual functions on a typical implementation? (i) Each class with virtual functions has a table…
- A method call such as shape.area() runs different code depending on whether shape refers to a Circle or a Square object at run time. Which…
- A Java class declares only the constructor Account(String id) and no other constructor. What happens with the statement new Account()?
- What is printed? java int x = 5; x = x++ + ++x; System.out.print(x);
- What is printed? cpp class A { public: int x; A(int v) : x(v) {} }; int main() { A a(5); A b = a; b.x = 9; cout << a.x << b.x; }