import java.awt.*; abstract class Vessel { double contents; abstract double volume(); abstract double circumf(); public void fill(double amount) { contents = contents + amount; contents = Math.min(contents, volume()); } } class Tank extends Vessel { double length, width, height; Tank(double length, double width, double height) { this.length = length; this.width = width; this.height = height; } double volume() { return length * width * height; } double circumf() { return 2 * (width + length); } public String toString() { return "Tank med indhold: " + contents; } } class Barrel extends Vessel { double radius, height; Barrel(double radius, double height) { this.radius = radius; this.height = height; } double volume() { return height * Math.PI * radius * radius; } double circumf() { return 2 * Math.PI * radius; } public String toString() { return "Tønde med indhold: " + contents; } } interface Colored { Color getColor(); } class ColoredBarrel extends Barrel implements Colored { private Color c; ColoredBarrel(double radius, double height, Color c) { super(radius, height); this.c = c; } public Color getColor() { return c; } } public class Vessel11 { static void printColor(Colored cobj) { System.out.println(cobj.getColor().toString()); } public static void main(String[] args) { Barrel b = new Barrel(15, 9); ColoredBarrel cb = new ColoredBarrel(2.5, 8, Color.red); printColor(cb); // printColor(b); Denne ordre kan ikke oversættes, da b ikke implementerer Colored. } }