wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about abstract classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question about abstract classes" Watch "A question about abstract classes" New topic

A question about abstract classes

Ranch Hand

Joined: Oct 30, 2000
Posts: 94
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...

Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3253
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());

Get Certified, Guaranteed!
(Now Revised for the new Pattern)

Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Consider Paul's rocket mass heater.
subject: A question about abstract classes
Similar Threads
abstract data type
Needs answers of some important questions
About Abstract Class
Some of you are experts this could be your next problem!
Communicate with the server without a browser.