So ABSTRACT classes are like EXAMPLE? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

So ABSTRACT classes are like EXAMPLE?

13th Feb 2017, 2:21 PM
Nochains
Nochains - avatar
2 Answers
+ 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.
13th Feb 2017, 3:50 PM
Tashi N
Tashi N - avatar
+ 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--; } }
13th Feb 2017, 3:16 PM
orsi