Germany allows people to opt out entirely, although there are a bunch of conditions and limitations. Most people don't, so the public system can still pay for itself.
Sadly in germany it's rather difficult to switch between public and private or no insurance. Or rather, it's very difficult to get back on a public insurance once you're private or self-insured. The best you can hope for is pulling it off once, maybe twice.
If you're avoiding paying into a system because you don't want to claim from it then letting you hop back on whenever you need it would destroy the system very quickly.
It's not that easy, luckily, if you're self-insured and have to take the service of a doctor, you can't switch just like that. It takes about a year of paper exchange with everyone involved to switch cleanly. Even then, any costs you started paying for from before will still have to be paid unless you're below a certain income bracket (or declare bankruptcy).
So if you were self-insured and broke a leg, then decided to switch back to insurance, you'd still be on the hook for the costs of the ongoing physiotherapy until it is healed back up. The insurance doesn't have to actually pay anything that happened before a switch (switching from public to public insurance or private to private doesn't have this limit, private to public and the other way round but you don't pay, your old insurance pays).
It's possibly one intention, though there are already laws that prevent you from going back to public insurance if you're over 55 years old as well as if you're over a certain income limit.
The only universal way to switch is to marry someone in public insurance.
Germany allows people to opt out entirely, although there are a bunch of conditions and limitations. Most people don't, so the public system can still pay for itself.