An abstract class is the sketch of your real class
EXAMPLE (4 STEPS)
- You make the abstract class, HOW?
package AbstractClass;
abstract class AbstractClass {
int x, y;
void moveTo(int newX, int newY) {
x = newX;
y = newY;
}
abstract void draw();
abstract void resize();
}
- You create the main class which EXTENDS the abstract class
package AbstractClass;
public class ExtensionClass extends AbstractClass {
}
- add unimplemented methods in the REAL class
- RESULT
ABSTRACT CLASS package AbstractClass;
abstract class AbstractClass {
int x, y;
void moveTo(int newX, int newY) {
x = newX;
y = newY;
}
abstract void draw();
abstract void resize();
} |
EXTENSION CLASS package AbstractClass;
public class ExtensionClass extends AbstractClass {
@Override
void draw() {
// TODO Auto-generated method stub
}
@Override
void resize() {
// TODO Auto-generated method stub
}
} |
you see that the extension class only contains 2 methods, that is because the other method exists in the abstract method. If you make a main class you with the object ExtensionClass you see you can use all the methods.