Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why an abstract class can be used?

 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Many people use here,why?
Damu
[ September 20, 2003: Message edited by: damu liu ]
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • 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
    • 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
    • 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
    • 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
    • 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
    • Quote
    • Report post to moderator
    Hi Phil., thank you!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic