File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question about calling Abstract Methods." Watch "Question about calling Abstract Methods." New topic
Author

Question about calling Abstract Methods.

Clark Johnson
Greenhorn

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: 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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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: http://aspose.com/file-tools
 
subject: Question about calling Abstract Methods.