Re: About abstract class and abstract method
- From: Thomas Fritsch <i.dont.like.spam@xxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 18:00:31 GMT
Sameer schrieb:
> t.beep();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();
You can *not* do this. The compiler-error is "Class java.awt.Toolkit is abstract and therefore cannot be instantiated"
You can do for example:
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?
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('$','@').
- Follow-Ups:
- Re: About abstract class and abstract method
- From: Sameer
- Re: About abstract class and abstract method
- References:
- About abstract class and abstract method
- From: Sameer
- About abstract class and abstract method
- Prev by Date: Re: HttpUtils.getRequestURL()
- Next by Date: Re: static block run several times (j2ee, apache tomcat)
- Previous by thread: About abstract class and abstract method
- Next by thread: Re: About abstract class and abstract method
- Index(es):
Relevant Pages
|
|