Just a random thought and a question. Can a smart contract written in solidity be inherited and if so, How?
Sure. Just like this:
contract Foo {
...
}
// Contract Bar inherits contract Foo
contract Bar is Foo {
...
}
Actually, one contract may inherit several contracts:
contract Foo {
...
}
contract Bar {
...
}
// Contract Zoo inherits contracts Foo and Bar
contract Zoo is Foo, Bar {
...
}
See documentation for details.
-
Okay, this is fine but what if one of my contract is already deployed on a network and now I am writing another contract and I want to inherit that contract. Is that possible? – vteja711 Nov 6 '19 at 9:11
-
1Sure, in case you have source code of the first contract, just import it and inherit from it. Your question is similar to the following C++/Java question: “May I inherit from a class, if I already created an instance of that class?”. Surely you can. – Mikhail Vladimirov Nov 6 '19 at 9:13