Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abstract Methods don't have body?

I am new to Java (reading books for 4 months now). So probably my question can appear too simple. My understanding is that abstract methods don't have a body and can't provide implementation

So how does this works?

public abstract void fillRect (int x, int y, with, height);

I did't point the question clearly. We've got abstract method. Why does it draw a rectangle if I doesn't provide a body, just parameters.

For example

public void paint (Graphics g) {

g.fillRect (5, 5, 30, 30);

}
like image 601
Max_S Avatar asked Dec 06 '22 06:12

Max_S


1 Answers

Also read docs

When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract.

like image 67
Suresh Atta Avatar answered Dec 20 '22 16:12

Suresh Atta