/** The Driver for the circuit thing */ public static void main(String[] args) { int x; int z; Random rand = new Random(); Super circuit; for (int i = 0; i < 5; ++i) { x = rand.nextInt(); x %= 3; x = Math.abs(x); z = rand.nextInt(); z %= 5; z = Math.abs(z); if (x == 0) circuit = new Series("Question #" + Math.abs((i + 1) - 6), z); else if (x == 1) circuit = new Parallel("Question #" + Math.abs((i + 1) - 6), z); else circuit = new Series_Parallel("Question #" + Math.abs((i + 1) - 6), z); circuit.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); circuit.setSize(420, 500); circuit.setVisible(true); } }
@Before public void setup() { a = new Base(); b = new Base(); c = new Super(); a.x = "a"; b.x = "b"; c.x = "c"; a.y = 11L; c.ignore = 12; }
public static void main(String[] args) { Super sup = new Sub(); // Upcast System.out.println("sup.field = " + sup.field + ", sup.getField() = " + sup.getField()); Sub sub = new Sub(); System.out.println( "sub.field = " + sub.field + ", sub.getField() = " + sub.getField() + ", sub.getSuperField() = " + sub.getSuperField()); }
public static void main(String[] args) { // 추상 클래스는 new로 생성될 수 없다. Super su = new Super() { @Override public void draw(String msg) { System.out.println("헛: " + msg); } }; su.draw("test"); Super[] ar = new Super[2]; ar[0] = new A(); ar[1] = new B(); String[] msg = {"사각형", "육각형"}; int i = 0; for (Super e : ar) { e.draw(msg[i]); i++; } }
private void testReferenceCalls() { // MessageSend, QualifiedSuperReference, QualifiedThisReference, // SuperReference, ThisReference Inner other = new Inner(); foo(); this.foo(); other.foo(); CoverageTest.this.foo(); super.foo(); Inner.super.foo(); CoverageTest.super.foo(); sfoo(); this.sfoo(); CoverageTest.sfoo(); Inner.sfoo(); Super.sfoo(); other.sfoo(); CoverageTest.this.sfoo(); super.sfoo(); Inner.super.sfoo(); CoverageTest.super.sfoo(); }
public void deep() { super.deep(); System.out.println("Sub.deep()"); }
public void t(Super obj) { // 重载的方法 System.out.println("Super"); // 根据obj运行时候引用的"对象类型"调用对象的方法 obj.t(); }
public static void main(String[] args) { Super s = new Sub(); s.call(); }
public static void main(String[] s) { String[] a = s[0].split(" "); String[] args = Arrays.copyOfRange(a, 1, a.length); Super.toClipboard(constructor(a[0], args)); }