Inheritance is a cornerstone of Java development, in the forms of abstract classes and interfaces. An abstract class isn’t concrete: it’s an idea to be drawn upon by extending classes. As plants draw upon sunlight to use photosynthesis, we can use an abstract class to create extended classes.
abstract class Foliage {
abstract int getHeight();
}
class Bush extends Foliage {
int height = 12;
int getHeight() {
return height;
}
}
class Tree extends Foliage {
int height = 60;
int getHeight() {
return height;
}
}
With our abstract class, all extending classes must have the getHeight function. Both Bush and Tree are classes extending abstract and can include other data, unlike objects implementing interfaces.
public class Abstract_Test {
public static void main(String[]args) {
Foliage f;
f = new Bush();
System.out.println("The common Lilac bush is about " + f.getHeight() + " feet (4 meters) tall.");
f = new Tree();
System.out.println("The average tree is about " + f.getHeight() + " feet (20 meters) tall.");
}
}
Unlike an interface, here we can adjust our abstract value, changing it to Bush, then Tree. Using abstract classes we can grow tall in our Java knowledge!

Interfaces are much different than abstract classes. Unlike an abstract class, you can only have abstract methods in an interface, declare an interface’s variables as constants, Interfaces are slow, lack constructors and even lack access modifiers, making everything public! Why ever use interfaces over abstract classes? Is there a reason you can think of? Leave an answer in the comments below and I will respond to your answer!
Follow my original code on my GitHub profile!