File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes General API class question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "General API class question" Watch "General API class question" New topic
Author

General API class question

Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
Hey,

I've found a class in the API that does almost everything I need it to do. However, in addition to what it does, I also need it to store a couple extra variables. The class is java.awt.polygon, and I need it to store simple variables like a name, id and description - no additional methods. It seems like this should be do-able. Is this a case where I am extending an existing class? Can someone point me to a place where I can learn more about how to do this?

Thanks!

Mike
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Mike McMahon:
...s this a case where I am extending an existing class? ...

That's exactly right. You want something that IS-A Polygon, but has extended capabilities. You do this with the keyword "extends"...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
Thanks Marc,

This is looking like a textbook example of a simple extension of a class.

In the example you've shown, I could then do stuff like :

Given that addPoints(int x, int y) is a method of the original polygon?

Thanks!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Exactly.

Note: Watch the capitalization. "myPolygon" is not the same as "MyPolygon."
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Sorry, don't have any pointers to examples.

You still might want to consider a containment relationship rather than an inheritance one. Depending on how much you want to use the new class.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: General API class question