This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about calling Abstract Methods.  RSS feed

Clark Johnson
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, I'd like to clarify that I did my homework and read about abstract classes on this site:

This question IS about abstract methods, but I'll use an example to help you understand where I am coming from.

Consider the Toolkit class in the java.awt package. Toolkit is an abstract class, and it has abstract methods. One of its abstract methods has the following signature:

public abstract Dimension getScreenSize()

This method is use to get the screen size. If you want to obtain the height of the screen, you'd call the method this way:


I understand that part. The part I don't understand is how you can call an abstract method given that abstract methods have no code.

Is it because Toolkit.getDefaultToolkit() returns a subclass of the Toolkit class which provides an implementation for the getScreenSize() abstract method of the Toolkit class?

That's my guess. If someone can clarify this for me, I'd appreciate it.
[ March 08, 2007: Message edited by: Clark Johnson ]
Ernest Friedman-Hill
author and iconoclast
Posts: 24215
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Clark,

Welcome to JavaRanch!

You guessed right. The "getDefault()" method is what's known as a factory method -- it creates (or fetches) an object for you without your needing to know the exact type. The implementation class will vary by platform, as Toolkit does various platform-specific things.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!