// SPDX-License-Identifier: MIT
// ==> PURPOSE OF INDICATING THAT UNDER WHICH LICENSE NUMBER THE CODE IS RELEASED
pragma solidity ^0.8.0;
contract ONE {
uint public Num;
string public name;
constructor() {
Num = 32;
name = "name of the pornstar";
}
function fuN() public pure returns (string memory) {
return "hello lanja";
}
}
contract two is ONE {
ONE p1 = new ONE();
function getNum() public view returns (uint) {
return Num;
}
}
You can access the Num variable from the two contract by calling the getNum() function, which returns the value of Num as a uint.
To access a local variable function in another contract without events, you can use function calls and return values. Here's an example:
// Contract A
contract A {
uint public num;
function setNum(uint _num) public {
num = _num;
}
function getNum() public view returns (uint) {
return num;
}
}
// Contract B
contract B {
A public contractA;
constructor(address _contractA) {
contractA = A(_contractA);
}
function getNumFromContractA() public view returns (uint) {
return contractA.getNum();
}
}
In the above example, Contract B has a reference to Contract A (contractA). By calling the getNumFromContractA() function in Contract B, you can access the getNum() function in Contract A and retrieve the value of the num variable.
// SPDX-License-Identifier: MIT
// ==> PURPOSE OF INDICATING THAT UNDER WHICH LICENSE NUMBER THE CODE IS RELEASED
pragma solidity ^0.8.0;
contract ONE {
uint public age = 22;
uint public row = 2;
function fuN() public pure returns (string memory) {
return "hello lanja";
}
function fun() public pure returns (uint) {
uint Num = 32;
return Num;
}
}
contract two is ONE {
ONE p1 = new ONE();
function update_values() public {
p1.age = 21;
}
}
You can access the age and row variables from the two contract by calling the respective functions: age() and row(). Additionally, you can call the fuN() function to get the string "hello lanja" and the fun() function to get the value of Num (which is 32).
However, please note that there is an error in the provided instructions where the closing parenthesis for the update_values() function is missing. Please make sure to fix this error for the code to compile correctly.
PARAMETERS PASSING TO THE PARENT CONSTRUCTOR ?MEDIUM EXAMPLE