Consider the following Solidity contract snippet. What will be the output when getValue() is called?
pragma solidity ^0.8.0; contract Simple { uint private value = 10; function getValue() public view returns (uint) { return value + 5; } }
Look at the value of value and what getValue() returns.
The variable value is 10. The function returns value + 5, so the output is 15.
What error will occur when compiling this Solidity contract?
pragma solidity ^0.8.0; contract Test { uint public x; function setX(uint _x) public { x = _x; } function setX(uint _x) public { x = _x * 2; } }
Check if Solidity allows two functions with the same name and parameters.
Solidity does not allow two functions with the same name and parameter types. This causes a TypeError.
Identify the reason this Solidity contract fails to compile.
pragma solidity ^0.8.0; contract Counter { uint count; function increment() public { count += 1; } function getCount() public view returns (uint) { return count; } }
Look carefully at the line inside increment().
The line count += 1 is missing a semicolon at the end, causing a syntax error.
data in this contract?Given this Solidity contract, what is the visibility of the variable data?
pragma solidity ^0.8.0; contract Storage { string data; function setData(string memory _data) public { data = _data; } function getData() public view returns (string memory) { return data; } }
State variables without explicit visibility are internal by default in Solidity.
In Solidity, state variables without a visibility modifier are internal by default, so data is internal.
Consider these two contracts. What will be the output of getName() when called on Child?
pragma solidity ^0.8.0; contract Parent { function getName() public pure virtual returns (string memory) { return "Parent"; } } contract Child is Parent { function getName() public pure override returns (string memory) { return "Child"; } }
Look at how getName() is overridden in Child.
The Child contract overrides getName() and returns "Child".