Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie needing some help!  RSS feed

 
Buburub
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create a stream can u mix the constructor?
Inputstream is = new FileInputStream( ) //legal?
OutputStream os = new FileOutputStream( ) //legal?
Normal Declaration:
FileOutputStream os = new FileOutputStream( )
And why would you mix it?
Thanks in Advance
=)
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Buburub",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
prabhat kumar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no default constructor for these classes.
however if u supply the constructor parameters than it is fully legal and it will be happy to compile.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are showing is just a common OO technique of putting an object in a wider container (variable).
Pet myPet = new Dog();
Since Dog in subclass of Pet it works fine.
Since FileInputStream is a subclass of InputStream it works fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!