jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why does OutputStream provide a constructor if its abstract? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Why does OutputStream provide a constructor if its abstract?" Watch "Why does OutputStream provide a constructor if its abstract?" New topic
Author

Why does OutputStream provide a constructor if its abstract?

Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
What is the purpose of defining a no-arg constructor in this class?
Thanks
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
If you look at the source code of OutputStream.java you'll notice that in fact they didn't define any constructor at all. The compiler thus added the default (no-arg) one which is reflected in the API. Since OutputStream is abstract you can't instantiate it directly anyway. I think it would have made more sense here to define one protected default constructor...
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1865
hi jim,
sometimes we need constructor in an abstract class too as it can have some methods implemented except atleast one abstract methods and can have instance variable shared by all the subclasses that needs to be initialized.
so we can have constructor in the abstract class.
hth;
regards
maulin


1. Have fun @ http://faq.javaranch.com/java/JavaRaq
2. Looking for simple infix2postfix conversion and postfix evaluation package? Click here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does OutputStream provide a constructor if its abstract?
 
Similar Threads
main method
IS CONCTRUCTOR IS A METHOD
WA #1.....word association
Constructor doubt - K&B Book
Can I overload a constructor with enum values?