Two Laptop Bag*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Why an abstract class can be used? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Why an abstract class can be used?" Watch "Why an abstract class can be used?" New topic
Author

Why an abstract class can be used?

Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi,
Many people use here,why?
Damu
[ September 20, 2003: Message edited by: damu liu ]
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
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

    Joined: Feb 26, 2003
    Posts: 240
    Hi,phil.,
    I mean why a abstract method can be used, it is not be implement.
    Regards
    DAmu
    Philippe Maquet
    Bartender

    Joined: Jun 02, 2003
    Posts: 1872
    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

    Joined: Feb 26, 2003
    Posts: 240
    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

    Joined: Jun 02, 2003
    Posts: 1872
    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

    Joined: Feb 26, 2003
    Posts: 240
    Hi Phil., thank you!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Why an abstract class can be used?