Do I have no choice but to inherit a class object in order to override one of its methods? Take this code for example...
//using Java
public class letsDraw extends Canvas {
public void paint(Graphics g) {
//there be lines and text drawn here
}
}
It inherits the Canvas class and allows me to override the paint method. However, if I try something like...
//using Java
public class letsDraw {
Canvas canvas; //member object of type Canvas
public void canvas.paint(Graphics g) {
//there be lines and text drawn here
}
}
...I get errors even though I thought all I was doing was overriding the method without inheriting it. Although I use Java in the examples above, I'm sure it similarly applies to C++/C# as well. Must I always inherit an object to override its methods or is there some other way?