You register a driver using Class.forName(...) (actually, that line allows the driver to register itself), then when you call DriverManager.getConnection(...), the DriverManager looks at the drivers it knows about and returns one that will handle the given database URL.
Everything from this point is done via interfaces. There are concrete classes behind these interfaces, but it is better to treat them as 'generic database classes' rather than the specific types because this makes your code independant of the specific database.
If you want to know what the actual class is, check System.out.println( rs.getClass().getName() );
DO NOT cast to this specific class! This ways leads to the dark-side of the
Java