con.openConnection() returns an object of type URLConnection. Now URLConnection is an abstract class and what it actually returns is an object of a concrete sub class. sub-class objects can be referenced by super class variable in this fashion.
When u have a variable of type subclass and you require that variable to point to the subclass object (currently pointed to by the superclass variable), you have to specifically cast it like this
A better solution (in my opinion) is to change the type of your variable:
One purpose of the superclass-subclass relationship is to provide an abstract interface through the superclass where each subclass provides the details for a specific implementation. Unless you absolutely need methods that are provided only by the subclass, you should use superclass references rather than subclass references.
This is a very fundamental concept in object-oriented design and programming. It would definitely be beneficial for you to study up on inheritence and related topics (such as polymorphism).