Extending the Color class

Hi, I’m trying to create additional methods for the class java.awt.Color:

public class Color extends java.awt.Color {

	private static final long serialVersionUID = 1L;

	public Color(float r, float g, float b) {
		super(r, g, b);
	}

	public static Color blend(Color c1, Color c2, float f) {
		return new Color(0F,0F,0F,0F);
	}

}

However, when the method blend is called Eclipse says “The method blend(Color, Color, float) is undefined for the type Color”.
Do you have any suggestions what may be the problem?

Are you sure you imported YOUR Color class? Maybe giving it a different name would avoid confusion

All my classes are in the same package so yes. Regarding the name, I’m trying to extend the pre-defined class java.awt.Color, not create another. It would be neat not having to create a whole new class just for one method, that’s why I’m trying to extend it.

It depends on how you’re calling it, but I suspect you’re trying to override a static method, which won’t work.

Don’t bother with a custom subtype of Color - that’s bad OOP. Instead just move your static blend() function into a utility class somewhere, then call it.

I guess I’ll have to do it that annoying way… Oh well, it’s a fun learning experience nonetheless, thanks for the help!

You cant extend classes with adding functions.
When you do, a new class is created.