Skip to content

Commit

Permalink
feat: inherited state variables declared
Browse files Browse the repository at this point in the history
  • Loading branch information
RaminRakhshani committed Jul 28, 2022
1 parent 808aaa6 commit 794a082
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pages/basics/inherited-state-variables.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
import Callout from 'nextra-theme-docs/callout'

# Inherited State Variables
# Inherited State Variables
- Unlike functions, state variables cannot be overridden by re-declaring it in the child contract.

```jsx
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

contract A {
string public name = "Contract A";

function getName() public view returns (string memory) {
return name;
}
}

// Shadowing is disallowed in Solidity 0.6
// This will not compile
// contract B is A {
// string public name = "Contract B";
// }

contract C is A {
// This is the correct way to override inherited state variables.
constructor() {
name = "Contract C";
}

// C.getName returns "Contract C"
}
```

0 comments on commit 794a082

Please sign in to comment.