Posted 27 January 2014 - 11:25 AM
Hello everyone,
today I was wondering: what's the use of abstract classes? They seem pretty useless to me.
Example code in Java (this concept will probably apply to other languages too)
What I don't understand is why you wouldn't just define (is this the correct name for creating methods?) the methods that MyClass needs, inside MyClass itself. Or is there something I'm missing? And are there situations in which an abstract class is useful?
Sorry if I'm being stupid right now, I'm not a Java developer or OOP specialist, you know. Just interested.
today I was wondering: what's the use of abstract classes? They seem pretty useless to me.
Example code in Java (this concept will probably apply to other languages too)
public abstract class MyAbstractClass {
public abstract void abstractMethod();
}
public class MyClass extends MyAbstractClass {
public void abstractMethod() {
System.out.println("This is a class");
}
}
(This example code was taken from the Dutch Wikipedia article about abstract classes.)What I don't understand is why you wouldn't just define (is this the correct name for creating methods?) the methods that MyClass needs, inside MyClass itself. Or is there something I'm missing? And are there situations in which an abstract class is useful?
Sorry if I'm being stupid right now, I'm not a Java developer or OOP specialist, you know. Just interested.