public abstract class Vehicle { public abstract void accept(VehicleVisitor visitor); public abstract int getType(); // to enable cached types, uncomment the two commented lines below // private final int cachedType = getType(); public int getCachedType() { // return cachedType; /* throw new UnsupportedOperationException(); // */ } }