Billy Jorgensen

Greenhorn
+ Follow
since Jan 07, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Billy Jorgensen

Hi everybody,

As I was reviewing an example used in the Head First Java book (second edition), bottom of page 367, I went to the API to look up a method, setPaint(), used in the example and noticed that all of the methods in the class (java.awt.Graphics2D) that setPaint() belongs to are abstract.

My question is, how do these methods work if they are all abstract? In the example in the book, there is this code:



FYI, the setPaint() method takes a Paint argument, and the example in the book creates a GradientPaint object (represented by the gradient variable), a subclass of the Paint class, so it is polymorphically OK for setPaint() method to take the gradient variable argument. This makes sense to me.

What I don't understand is why we're using the Graphics2D setPaint() method if it is abstract? An abstract method has no code implementation, which would mean the abstract setPaint() method in the Graphics2D class has no code implementation, which makes me wonder how it can set the Graphics2D class' Paint attribute in the first place? If we wanted to set a Paint attribute, wouldn't we have to create a subclass of Graphics2D that provides method implementation code for setPaint(), thereby providing a way to set a Paint attribute? Is there some unique functionality going on in this class (and other similar classes) that I'm not aware of?
16 years ago