Now I would like to make introduction about the difference between Abstract Class and Interface in Java.
For Abstract Class may contains abstract method and abstract property, but Interface may contains only normal method without encapsulation and no method body implementation.
We use abstract class and interface as base class in Java.

 //Abstarct Class
public abstract class Entity {
private int id;
private Color c;
public void setID(int id) { this.id = id }
public int getID() { return id; }
public void setColor(Color c) { this.c = c; }
public Color getColor() { return c; }
public abstract void paint(Graphics g);
}

//Interface

public interface Entity {
void setID(int id) ;
int getID();
void setColor(Color c);
Color getColor() ;
void paint(Graphics g);
}
Advertisements