In one personal finance book I read that if a company is located in a country with credit rating X it can't have credit rating better (lower - i.e. further from AAA level) than X.
This is simply wrong. Real world evidence proves it wrong. Automatic Data Processing (ADP), Exxon Mobile (XOM), Johnson & Johnson (JNJ), and Microsoft (MSFT) all have a triple-A rating today, even though the United States doesn't. Toyota (TM) remained triple-A for many years even after Japanese debt was downgraded.
The explanation was the following: country has rating X because risk of doing business with it is X and so risk of doing business with any company located in that country automatically can't be better than X.
When reading financial literature, you should always be critical. Let's evaluate this statement. First off, a credit rating is not the "risk of doing business." That is way too generic. Specifically, a credit rating attempts to define an individual or company's ability to repay it's obligations. Buying treasuries constitutes as doing business with the gov't, but you can argue that buying stamps at USPS is also doing business with the gov't, and a credit rating won't affect the latter too much.
So a credit rating reflects the ability of an entity to repay it's obligations. What does the ability of a government to repay have to do with the ability of companies in that country to repay? Not much. Certainly, if a company keeps it's surplus cash all in treasuries, then downgrading the government will affect the company, but in general, the credit rating of a company determines the company's ability to pay.