• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about abstract classes

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello!!!
This is about abstract classes.From whatever I have learnt till now abstract classes can not be instantiated.But if we look at URL class it has got a method url.openConnection() which according to jdk documentation

"Returns a URLConnection object that represents a connection to the remote object referred to by the URL. "
Now URLConnection class as per my knowledge is an abstract class...so whats the magic in openConnection method which causes instantiation of an abstract class.
Please correct me if i am wrong...

------------------
Cheers
Jayram
 
Enthuware Software Support
Posts: 4818
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no magic. What happens when you do, hashtable.keys() ? It returns an Enumeration. But Enumeration is an interface!! How can it instantiate an interface?
In all such cases, the method returns an object of either a class that implements the interface or a class that extends from the abstract class... as the case may be.
You can actually try this:
Enumeration enum = hashtable.keys();
System.out.println( enum.getClass());
HTH,
-Paul.


------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
reply
    Bookmark Topic Watch Topic
  • New Topic