0
So ABSTRACT classes are like EXAMPLE?
2 Antworten
+ 5
The abstract class is something like a template, that fits all the classes you want to extend from the abstract class. You can declare methods there that the extending classes will have to implement (override). You can also declare fields there which are common for all extending classes.
See
http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
for further information.
+ 1
abstract class Animal{
protected int hungry;
abstract void sound();
abstract void eat();
}
public class Cat extends Animal {
public Cat(){
hungry = 5;
}
public void sound(){
System.out.println("meow");
}
public void eat(){
hungry--;
}
}