C++ Code Reorder Medium +20 XP
Class with Constructor
Arrange the C++ class properly.
Click lines in the correct order
Available lines7 left
Your order
Click lines above to build your solution.
Show answer and explanation
Answer: class Rectangle {
private:
int width, height;
public:
Rectangle(int w, int h) : width(w), height(h) {}
int getArea() { return width * height; }
};
Class declaration, then private members, then public constructor and methods, then semicolon.
Hint: Private data first, public interface second.
What this challenge tests
Code Reorder in C++: classes, access-modifiers.