I noticed there are two methods to call the contract's functions in Solidity as follow.
// Base contract
contract A {
function X() public pure returns (string memory s) {
s = 'Base contract function X';
}
}
// Inherited contract
contract B is A {
function Y() public pure returns (string memory s) {
s = string.concat(X(), ' + Inherited contract function Y');
}
}
// Contract with new key word
contract C {
A contractA = new A();
function Z() public view returns (string memory s2) {
s = string.concat(contractA.X(), ' + Contract C function Z');
}
}
I don't understand the difference between contract B and C, especially in what case should I use inheritance, or new key word to call a function?