File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Question about calling Abstract Methods. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question about calling Abstract Methods." Watch "Question about calling Abstract Methods." New topic

Question about calling Abstract Methods.

Clark Johnson

Joined: Mar 08, 2007
Posts: 20
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

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Question about calling Abstract Methods.
It's not a secret anymore!