Campbell Ritchie wrote: [...] Start by reading our FAQ which will probably answer your question.
This is (pretty much) the code from the FAQ. I understand (reasonably well) why it does what it does. But, what caught my attention was the discussion on better coding style (see line 6). I'm not entirely certain on how or why this works. If I understand correctly, as long as I declare an instance of class Foo f = new Foo;, I can make calls directly to Foo without using the declared variable name?
There are worse crimes than burning books. One of them is not reading them. Ray Bradbury
Not sure I understand the question. If you declare a variable, any static members are bound at compile‑time and calling them is done on the Foo type. If you create it as a Bar, static members are still bound at compile‑time. Instance members are dynamically bound (dynamic ≠ static, which might be why they chose the keyword static) at run‑time, so you get polymorphism. Because of the potential for confusion, you ought always to use the class name: Foo.myStaticMethod(...); and you can do that whether or not there are any variables of type Foo.
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad: