About abstract class and abstract method

Discussion in 'Java' started by Sameer, Aug 30, 2005.

  1. Sameer

    Sameer Guest

    Consider the declaration from Java API:

    public abstract class Toolkit extends Object

    This abstract class java.awt.Toolkit contains one abstract method beep.

    public abstract void beep()

    The Java Tutorial says that-
    "An abstract class can contain abstract methods - methods with no
    implementation. In this way, an abstract class can define a complete
    programming interface for its subclasses but allows its subclasses to
    fill in the implementation details of those methods."

    But we can make instance of Toolkit and make use of this method.
    Toolkit t= new Toolkit();
    t.beep();

    How can we make instance of this abstract class and make use of one of
    its abstract method?
    Who fill 'implementation details' for the beep method?

    -Sameer
     
    Sameer, Aug 30, 2005
    #1
    1. Advertising

  2. Sameer schrieb:
    > Consider the declaration from Java API:
    >
    > public abstract class Toolkit extends Object
    >
    > This abstract class java.awt.Toolkit contains one abstract method beep.
    >
    > public abstract void beep()
    >
    > The Java Tutorial says that-
    > "An abstract class can contain abstract methods - methods with no
    > implementation. In this way, an abstract class can define a complete
    > programming interface for its subclasses but allows its subclasses to
    > fill in the implementation details of those methods."
    >
    > But we can make instance of Toolkit and make use of this method.
    > Toolkit t= new Toolkit();
    > t.beep();

    You can *not* do this. The compiler-error is "Class java.awt.Toolkit is
    abstract and therefore cannot be instantiated"
    >
    > How can we make instance of this abstract class and make use of one of
    > its abstract method?
    > Who fill 'implementation details' for the beep method?

    You can do for example:
    Toolkit t= Toolkit.getDefaultToolkit();
    t.beep();
    You will get a non-abstract subclass of java.awt.Toolkit here.
    On Windows you get a sun.awt.windows.WToolkit, which has an
    implementation for beep()

    >
    > -Sameer
    >



    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
     
    Thomas Fritsch, Aug 30, 2005
    #2
    1. Advertising

  3. Sameer

    Sameer Guest

    If I subclass the Toolkit class and try to write implementation of
    beep() method, what may be the coding?
    Is it depends on the operating system for implementation?

    Can anybody provide some examples which classes the abstract class of
    Java and provide some useful implementation for the abstract methods?

    Java subclasses of the abstract classes do this? Then why may be the
    abstract classes designed?
     
    Sameer, Aug 30, 2005
    #3
  4. Sameer

    Roedy Green Guest

    On 30 Aug 2005 10:32:06 -0700, "Sameer" <> wrote or
    quoted :

    >How can we make instance of this abstract class and make use of one of
    >its abstract method?


    See http://mindprod.com/jgloss/abstract.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Aug 30, 2005
    #4
  5. Sameer

    Roedy Green Guest

    On 30 Aug 2005 10:32:06 -0700, "Sameer" <> wrote or
    quoted :

    >This abstract class java.awt.Toolkit contains one abstract method beep.


    Some Sun classes, such as java.awt.Toolkit are abstract or only have
    private constructors. This is infuriating. Where do you get one of
    these objects from??

    The key is SOMEWHERE in there is a static factory method that will
    create such objects for you. For the beep problem see
    http://mindprod.com/jgloss/beep.html


    You often seen this pattern when Sun wanted to make implementations
    pluggable. The implementation can be replaced at run time by one
    tuned to the platform or by a third party enhancement.

    The entire JCE works this way.

    What we need is a browsing tool of the JavaDocs what will find those
    factories for you.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Aug 31, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Kaeppler
    Replies:
    1
    Views:
    443
    R.F. Pels
    May 22, 2005
  2. Uzytkownik
    Replies:
    3
    Views:
    594
    Uzytkownik
    Apr 3, 2005
  3. Replies:
    4
    Views:
    823
    Rolf Magnus
    May 17, 2006
  4. Chris Zopers

    Abstract method in non-abstract class

    Chris Zopers, Aug 8, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    375
    Göran Andersson
    Aug 8, 2008
  5. Stefan Ram
    Replies:
    27
    Views:
    743
    Stefan Ram
    Aug 17, 2009
Loading...

Share This Page