ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
class Shape {
public:
Shape& operator=(const Shape&) = delete;
Shape() = default;
};
int main() {
Shape a, b;
a = b;
}- A. It compiles and copies b into a
- B. Compilation error: Shape's copy assignment operator is deleted
- C. It compiles but does nothing
- D. It throws a run-time exception
Correct answer: B. Compilation error: Shape's copy assignment operator is deleted
Explicitly deleting the copy assignment operator removes it from overload resolution entirely; any attempt to use `=` for assignment between two Shape objects, like `a = b;`, is rejected at compile time.
More OOP with C++ and Java questions
- What is printed? java class Parent { protected int score = 50; int getScore() { return score; } } class Child extends Parent { Child() {…
- What is printed? java class Base { void greet() { System.out.print("Base "); helper(); } private void helper() {…
- What is printed? cpp struct Base { virtual void save() { cout << "BaseSave "; } }; struct Derived : Base { void save() override { cout <<…
- What is printed? java class Animal { String sound() { return "..."; } } class Dog extends Animal { @Override String sound() { return…
- What is printed? cpp struct Base { virtual int value() const { return 10; } }; struct Derived : Base { int value() const override { return…
- What is printed? java interface Payable { double rate(); default double monthly(double hours) { return hours rate(); } } class Intern…