> For the complete documentation index, see [llms.txt](https://chihaolu.gitbook.io/all-in-one-solidity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chihaolu.gitbook.io/all-in-one-solidity/part-i-basic/chapter-5-han-shi-function/constructor.md).

# 【Constructor】

建構子（constructor）是一個在合約被創建時只會跑一次的函數，像是佈署到鏈上時，可用於初始化或宣告某些我們希望一開始就執行的變數。

```solidity
contract myContract {
    uint a;
    constructor() public {
        a = 0;
    }
}
```

關於建構子有以下規定：

1. 一個 Contract 只能有一個建構子。
2. 可視性可以為 `public` 或 `internal`
3. 如果一個 Contract 被標示為 `internal`，則其為 Abstract Contract
4. `constructor` 也可以像普通函數一樣有參數。
