Drinking in Public in Germany
Yes, you can drink in public in Germany. Whether you are walking down the street or riding in a train, you are free to drink whatever you like in public. Depending on whether or not a soccer game is going on, the number of people doing so however is often rather low, and most noticeable near bars and clubs at night.
Before you go thinking that it would be a swell idea to crack open a beer on the bus, it's worth bearing in mind that most public transportation authorities that run city buses and trams have specific policies against eating and drinking while riding. They'll leave you alone if you are drinking water or some other soft drink, but if the driver or ticket checker sees you with an open container, or if you're causing a ruckus, they'll probably tell you to get out.
As a general point (a mild pet peeve), if you're going to drink in public, make sure that any bottles that don't have a deposit (Pfand) make it into a trash can. However, if you want to do a solid by the typically homeless individuals which will look in the city trash cans for deposit bottles, leave them next to the trash can. They'll get taken.
Also, just because you can drink in public, doesn't mean you have license to be a public nuisance. Germany is a country that feels strongly about teaching young people how to handle drinking alcohol responsibly, and as a point of order, Germans don't much appreciate and aren't terribly interested in dealing with intoxicated individuals.
All that being said, yes, you are free to crack open your beer wherever you are (and you'll likely see people doing so at any hour of the day over the course of your time here). It's a nice change of pace, particularly during city festivals, where you are free to get your drink and wander through, without having to worry about staying within some marked area.