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;
}
  1. A. It compiles and copies b into a
  2. B. Compilation error: Shape's copy assignment operator is deleted
  3. C. It compiles but does nothing
  4. 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

Exams that ask this topic