1. What is Function Visibility?

In Solidity, every function can have one of four visibility specifiers:

If you don’t explicitly declare it… the compiler picks a default.


2. Behavior Before Solidity 0.5.0

Before Solidity 0.5.0 (old versions), the default visibility for functions was public.

That means if you forgot to specify visibility, your function was exposed to the world.

Example (pre-0.5.0):

pragma solidity ^0.4.24;

contract Wallet {
    address owner;

    function Wallet() { // constructor (old syntax)
        owner = msg.sender;
    }

    // Forgot to add visibility
    function kill() {
        selfdestruct(owner);
    }
}

Looks like only the contract itself should call kill(), right?

But since no visibility is specified, kill() defaults to public.

That means anyone can call it → anyone can self-destruct your wallet.

This happened in real contracts, and money was lost.


3. Post-0.5.0 Changes