ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
void f(int) { cout << "int "; }
void f(double) { cout << "double "; }
int main() {
f('a');
f(2.5f);
}- A. double double
- B. int double
- C. int int
- D. Compilation error: ambiguous call
Correct answer: B. int double
char to int is an integral promotion, which beats the char-to-double conversion, so f('a') picks f(int). float to double is a floating-point promotion, which beats float-to-int, so f(2.5f) picks f(double).
More OOP with C++ and Java questions
- What is printed? cpp struct A { A() { cout << "C"; } A(const A &) { cout << "K"; } ~A() { cout << "D"; } }; void f(A a) { } int main() { A…
- What is printed? cpp class A { public: static int count; A() { count++; } ~A() { count--; } }; int A::count = 0; int main() { A a, b; { A…
- Which line fails to compile? cpp struct Shape { virtual double area() = 0; }; struct Circle : Shape { }; struct Square : Shape { double…
- class D : private B { ... }; where B has public int x, protected int y and private int z. Which is correct?
- Which of these is a checked exception in Java?
- A parent class declares protected void run(). Which overriding declaration in a subclass compiles?