专用车网站建设哪家好,国内虚拟主机WordPress,李宁运动服网站建设规划书,成都网站维护多少钱修饰符可见性描述public在合约内和合约外都可以被访问#xff0c;即合约内外部都可以调用该函数。这种类型的函数可以被合约内和合约外的任何地址调用。private只有在当前合约内可以被访问#xff0c;即只有合约内可以调用该函数。这种类型的函数只能在合约内部被调用。exter…修饰符可见性描述public在合约内和合约外都可以被访问即合约内外部都可以调用该函数。这种类型的函数可以被合约内和合约外的任何地址调用。private只有在当前合约内可以被访问即只有合约内可以调用该函数。这种类型的函数只能在合约内部被调用。external在合约外部可以被访问但在合约内部不能被访问。这种类型的函数只能被合约外的地址调用。internal只有在当前合约内以及继承合约中可以被访问。这种类型的函数只能在当前合约内部和合约继承树上的合约内部被调用。示例代码pragma solidity ^0.8.7;contract FunctionVisibility {uint public num; // 公有变量constructor() {num 0;}function publicFunc() public view returns (uint) {//公有函数return num;}function privateFunc() private view returns (uint) {//私有函数return num;}function externalFunc() external view returns (uint) {//外部函数return num;}function internalFunc() internal view returns (uint) {//内部函数return num;}function callPrivateFunc() public view returns (uint) {return privateFunc(); // 只能在合约内调用}function callExternalFunc() public view returns (uint) {return externalFunc(); // 只能在合约外调用}function callInternalFunc() public view returns (uint) {return internalFunc(); // 只能在当前合约内或继承的合约内调用}
}注num:公有变量可以被合约内外的所有地址访问。publicFunc :公有函数也可以被合约内外的所有地址访问。privateFunc :私有函数只能在当前合约内部被访问。externalFunc :外部函数只能在合约外被访问。internalFunc :内部函数只能在当前合约内部以及继承的合约内部被访问。