/** * This is an illustration of an abstract class (ModernArtist). * You can declare variables (e.g., artists) of this class. * However, you cannot instantiate it directly. * You must instantiate derived classes (e.g., cubist) * * NOTE: although there is an abstract method getNumber() in * the abstract class, in general, this is not needed in * an abstract class. */ abstract class ModernArtist { String name; int number; ModernArtist(String n) { name = n; } public String getName() { return name; } public abstract int getNumber(); } class cubist extends ModernArtist { cubist(String n) { super(n); } public int getNumber() { return number; } } public class Artist { public static void main(String[] args) { ModernArtist[] artists; artists = new ModernArtist[3]; for (int i = 0; i < 3; i++) { artists[i] = new cubist("Picasso"); } for (int i = 0; i < 3; i++) System.out.println("modern artist: " + artists[i].getName()); } }