here is the link for API documentation of Outputstream abstract class .You will find a default constructor
http://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#OutputStream%28%29
here is the link for API documentation of Outputstream abstract class .You will find a default constructor
http://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#OutputStream%28%29
The class has to have at least one constructor, because all Java classes have constructors. Additionally, subclasses will have to chain to it - so it's got to be at least protected
accessibility. The constructor doesn't need to do anything, so the authors decided not to provide an explicit one. Now, from JLS 8.8.9:
The default constructor has the same accessibility as the class
That's why it's public
. It could have been explicitly provided as:
protected OutputStream() {
}
... or better yet, the JLS could have made it so that public abstract class default constructors were implicitly protected. However, it does no harm for it to be public.
The default constructor is always present in every java class, if there is no other constructor defined. This makes sense, since you need to have some way to instantiate the class. For abstract classes there still needs to be a constructor that can be called by the constructors of the sub-classes. Even if you do not explicitly write a super()
statement as the first statement of a constructor, it is implicitly added by the compiler and executed at runtime.
Every class in Java must have a constructor. What you say I understand is that when I cannot create its object what's the use of constructor ?? But its the rule and any subclass when created calls the base class constructor like a chain process. It could have been made protected
I think the question is very relevant. The no-argument constructor is implicitly available if no constructor is explicitly defined.
Since the abstract OutputStream class has no other constructors defined, the no-arg constructor is not necessary.