Re: About abstract class and abstract method



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('$','@')

.



Relevant Pages

  • RE: Overridden methods
    ... >> overriding method then do some common functionality. ... Programs don't use instances of an abstract class, ... subclasses. ... transmitted without the written permission of the copyright owner. ...
    (perl.beginners)
  • Re: Constructor Accessibility - protected ctor inside public class with internal parameter
    ... instance of an internal class to the abstract class' ctor. ... subclasses can see the ctor. ...     visible to code within the library OR ANY subclasses. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Factory method
    ... > factory method in my abstract class that creates subclasses. ... > constructor in my subclasses must be able to call the constructor in my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Factory method
    ... > factory method in my abstract class that creates subclasses. ... > constructor in my subclasses must be able to call the constructor in my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: design question
    ... > Say I have an abstract class A and 2 subclasses, ... > I want a static method in class A that lists all the objects of a type in ... B inherits the listObjects method from A so the ...
    (comp.lang.java.help)