Token and Ownable with specified functionsMyToken that inherits from both Token and OwnableMyToken that calls functions from both base contractsMyToken contract to show multiple inheritance worksToken and Ownable with specified functionsMyToken that inherits from both Token and OwnableMyToken that calls functions from both base contractsMyToken contract to show multiple inheritance worksTokenToken with a public function totalSupply that returns 1000.Define a contract named Token. Inside it, add a public pure function totalSupply that returns the number 1000.
OwnableOwnable with a public function owner that returns the address 0x1234567890123456789012345678901234567890.Create a contract named Ownable. Add a public pure function owner that returns the fixed address 0x1234567890123456789012345678901234567890.
MyToken with multiple inheritanceMyToken that inherits from both Token and Ownable. Add a public function info that returns both the total supply and owner address by calling the inherited functions.Define MyToken inheriting from Token and Ownable. Add a function info that returns a tuple with totalSupply() and owner().
MyToken contract outputinfo() on MyToken and prints the total supply and owner address separated by a space.Create a public function test that calls info(), converts the results to strings, and returns them separated by a space.
What is the main purpose of multiple inheritance in blockchain smart contracts?
Which of the following is the correct syntax to inherit from two contracts A and B in Solidity?
contract C is ? {}contract C is A, B {}.Consider the following Solidity contracts:
contract A {
function greet() public pure virtual returns (string memory) {
return "Hello from A";
}
}
contract B {
function greet() public pure virtual returns (string memory) {
return "Hello from B";
}
}
contract C is A, B {
function greet() public pure override(A, B) returns (string memory) {
return super.greet();
}
}What will C().greet() return?
super.A then B. Calling super.greet() calls A's greet due to C3 linearization order C, A, B.Given the contracts below, what is the error in contract C?
contract A {
function foo() public pure returns (string memory) {
return "A";
}
}
contract B {
function foo() public pure returns (string memory) {
return "B";
}
}
contract C is A, B {
// Missing override keyword
function foo() public pure returns (string memory) {
return super.foo();
}
}override keyword.foo lacks override(A, B), causing a compilation error.You have two contracts:
contract Token {
function transfer() public pure virtual returns (string memory) {
return "Token transfer";
}
}
contract Mintable {
function transfer() public pure virtual returns (string memory) {
return "Mintable transfer";
}
}
contract MyToken is Token, Mintable {
function transfer() public pure override(Token, Mintable) returns (string memory) {
return string.concat(Token.transfer(), " & ", Mintable.transfer());
}
}What will MyToken().transfer() return?
transfer calls both Token.transfer() and Mintable.transfer() explicitly.Token.transfer() first, then Mintable.transfer() with " & " in between.Pass the test and this pattern moves unknown