• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about calling Abstract Methods.

 
Clark Johnson
Greenhorn
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: http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html

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:

Toolkit.getDefaultToolkit().getScreenSize().height;

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
Marshal
Pie
Posts: 24208
35
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