ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
int a = 5; int &r = a; r = 10; int b = 20; r = b; b = 30; cout << a << " " << r;
- A. 30 30
- B. 20 30
- C. 10 30
- D. 20 20
Correct answer: D. 20 20
A reference is bound once, at initialisation, and cannot be re-seated. r = b copies the value 20 into a; it does not make r refer to b. So later b = 30 has no effect: a and r are both 20.
More OOP with C++ and Java questions
- What is printed? java class R implements AutoCloseable { String n; R(String n) { this.n = n; System.out.print("o" + n + " "); } public…
- What is printed? cpp struct B { virtual void f(int x = 1) { cout << "B" << x; } }; struct D : B { void f(int x = 2) override { cout << "D"…
- What is printed? java class T { static String hi() { return "hi"; } } // in main: T t = null; System.out.print(t.hi());
- What is printed? java char x = 'A'; int i = 0; System.out.print(true ? 1 : 2.0); System.out.print(" "); System.out.print(true ? x : i);
- 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…