'Java2D method call without class
I just started to learn Java and tried to draw some rectangles.
I have run this example and can't understand one thing: class ShapesDemo2D has a constructor:
public void init() {
//Initialize drawing colors
setBackground(bg);
setForeground(fg);
}
I understand that setBackground is a method.
- But how can it be called without a class or instance reference?
This is a method of an abstract Component class in Component.java file.
- Shouldn't it be like
Component.setBackground(bg)orcomponentInstance.setBackground(bg)?
But Component is an abstract class, so it can't be instantiated, and it's methods can not be called.
- So how it is possible to call this method?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
