• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Wierd I/0 Constructors

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am refering "The Complete Reference" 4 I/O . Here while creating a instance of the FileInputStream its is written
InputStream f = new FileInputStream("filename.ext")//is this wrong?
AND NOT
**FileInputStream f = new FileInputStream("filename.ext");**
I dont understand y and how?
BUT on the contrary ByteArrayInputStream is instansiated as expected ie
**ByteArrayInputStream b = new ByteArrayInputStream(buf);**
My Question is can I instansiate ByteArrayInputStream like this:
**InputStream b = new ByteArrayInputStream(buf);**
AND PushbackinputStream which has a constructor like this:
**PushbackinputStream(InputStream is,int numbytes)
while instansiating it instead of passing a object of a InputStream as the first argument an object of a ByteArrayInputStream is passed
again y? and wat r the rules 4 doing such a thing can i do this with any constructor.(R there long code questions on I\O in the paper coz i heard that knowing all the constructors properly sud be enough or will i need to write some codes myself??)
AMIT ROY
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All your questions can be attributed to one thing:
"An object of a subclass can ne referred to by a referrence of type of its superclass."
Since Inputstream is the superclass of all input streams,
you can use the statement as you described.
Hope this can help
Bin Zhao
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic