package org.esjava.samples; abstract class Animal { /* Data Type Default Value (for fields) boolean false byte 0 short 0 int 0 long 0L float 0.0f double 0.0d char '\u0000' String (or any object) null boolean false */ final String name; Animal(final String name) { this.name = name; } static void MessageBox(String msg) { // System.out.println(msg); alert(msg); } void move(long meters) { MessageBox(name + " moved " + meters + "m."); } abstract void move(); static final char U_YIN_YANG = '\u262F'; // ☯ static final char U_CAUTION_SIGN = '\043'; // # } class Snake extends Animal { Snake(String name) { super(name); } @Override void move() { MessageBox("Slithering \u2621 ..."); super.move(3); } @Override void move(long meters) { super.move(2 * meters); } } class Horse extends Animal { Horse(String name) { super(name); } @Override void move() { Horse.MessageBox("Galloping \041\u0021!"); super.move(-052l); } } public class BabelEvaluate { public static void main(String[] args) { Animal[] animals = new Animal[] { new Snake(Animal.U_CAUTION_SIGN + "Sammy the Python"), new Horse(Animal.U_YIN_YANG + "Tommy the Palomino") }; for (int in = 0; in < animals.length; in++) { animals[in].move(); // animals[in].move(in + 5); } } } /* BabelEvaluate.main(42); */
Created and maintained by Oleg Mazko