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

Why an abstract class can be used?

 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Many people use here,why?
Damu
[ September 20, 2003: Message edited by: damu liu ]
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi damu,
What's your question exactly ?
  • Why people use FileChannel ?
  • Why FileChannel is abstract ?
  • How people can use it as it is abstract ?
  • ... ?


  • Best,
    Phil.
     
    Bigwood Liu
    Ranch Hand
    Posts: 240
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,phil.,
    I mean why a abstract method can be used, it is not be implement.
    Regards
    DAmu
     
    Philippe Maquet
    Bartender
    Posts: 1872
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi damu,

    I mean why a abstract method can be used, it is not be implement.


    As FileChannel is a class, you probably wonder how such an abstract class can be used as it is not implemented.
    You may see an abstract class a bit like an interface which could be implemented partially. That's the case for FileChannel.
    As an abstract class is - at best - partially implemented (or not at all like an interface), you cannot instantiate such a class. But you can instantiate a fully implemented class which would extend the abstract class.
    So, as far as FileChannel is concerned, you cannot instantiate it yourself. But by calling the FileChannel getChannel() method of RandomAccessFile (or of FileInputStream, or FileOutputStream), you get a valid FileChannel instance which in fact is an instance of a class extending FileChannel and which is not abstract.
    Best,
    Phil.
     
    Bigwood Liu
    Ranch Hand
    Posts: 240
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,phil., thank you very much!

    But by calling the FileChannel getChannel() method of RandomAccessFile (or of FileInputStream, or FileOutputStream), you get a valid FileChannel instance which in fact is an instance of a class extending FileChannel and which is not abstract.


    I am still a little confused. Since the FileChannel is not fully implemented, and it doesn't have a subclass, which means there isn't anyone writes the code of the abstract methods, then how can the computer know what to do even if I getChannel()?
    Regards,
    Damu
     
    Philippe Maquet
    Bartender
    Posts: 1872
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi damu,

    I am still a little confused. Since the FileChannel is not fully implemented, and it doesn't have a subclass


    It has at least one subclass, FileChannelImpl, used by RandomAccessFile FileInputStream and FileOutputStream, and ... which is not documented. As FileChannelImpl IS-A FileChannel, it can be returned as a FileChannel.
    Best,
    Phil.
     
    Bigwood Liu
    Ranch Hand
    Posts: 240
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Phil., thank you!
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic