It's not something they can decide unilaterally
In essence, in all these scenarios all the other countries will make a decision whether to consider B the same as A or not; and in the particular scenarios you describe, usually everyone will consider them as the same. The name of the country as decided by its legislature is pretty much irrelevant. It's generally in everyone's best interest to have some form of continuity - it's worth noting that in the in case of a totally new country at the very beginning it has no rights to anything whatsoever including the sovereignty over its territory, they would want diplomatic recognition of their sovereignty at least from all their immediate neighbors, which generally would be conditional on them acknowledging continuity and asserting that they'll honor all the obligations of the previous regime.
In the case of a major change in regime, or territory, or country splitting, there may be other options. The other answer notes USSR->Russian Federation transition, but it's also relevant to look at the transition from Russian Empire to USSR. USSR disclaimed continuity from the Russian Empire and refused its foreign obligations and debt (https://en.wikipedia.org/wiki/Repudiation_of_debt_at_the_Russian_Revolution). This was followed by all the major powers, including previous allies of the Russian Empire, sending troops and other resources against the Red government, and openly supporting various other factions in the Russian civil war (who would acknowledge continuity from the Russian Empire and its obligations). It wasn't until the military victory of USSR in that war that its sovereignty as a new state was recognized by others.
It's worth noting that different countries may decide differently - some may consider that B is the continuation of A and some may not. An interesting example may be the situation of People's Republic of China and Republic of China(Taiwan), especially in the 1960s/1970s as the consideration of which country is the continuation of the pre-WW2 China changed over time.