---
# System prepended metadata

title: Rectangle2.cpp

---

# Rectangle2.cpp

```cpp=
#include<stdio.h>

class Rectangle { // 定義一個 Rectangle 類型
    public: 
    int width;
    int height;
    int area() {
        return width * height;
    }
};

int main() {
    Rectangle r1; // 宣告一個 Rectangle 「物件」，名字叫做 r1
    Rectangle r2; // 宣告一個 Rectangle 「物件」，名字叫做 r2
    
    r1.width = 3;
    r1.height = 4;
    r2.width = 5;
    r2.height = 6;
    printf("%d\n", r1.area());
    printf("%d\n", r2.area());
    return 0;
}
```