Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2005

Tip: Looking for answers? Try searching our database.

About abstract class and abstract method

Thread view: 
Sameer - 30 Aug 2005 18:32 GMT
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
Thomas Fritsch - 30 Aug 2005 19:00 GMT
Sameer schrieb:
> Consider the declaration from Java API:
>
[quoted text clipped - 13 lines]
> 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

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

Sameer - 30 Aug 2005 19:41 GMT
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?
Roedy Green - 30 Aug 2005 21:32 GMT
>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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 31 Aug 2005 01:59 GMT
>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.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.