import jeliot.io.*;
public class SimulasiReference {
public static void main() {
System.out.print("\nPakai kelas\n");
Bilangan x1 = new Bilangan(5);
Bilangan y1 = new Bilangan(6);
x1.keluaran();
y1.keluaran();
x1.swap(x1, y1);
System.out.print("\nSetelah swap pakai kelas : \n");
x1.keluaran();
y1.keluaran();
}
}
public class Bilangan {
public Bilangan (int x) { // konstruktor
a = x;
}
public final void swap(Bilangan a, Bilangan b) {
int temp;
temp = a.a;
a.a = b.a;
b.a = temp;
}
public final void keluaran() {
System.out.println("Bilangannya : " + a);
}
private int a;
}
Friday, February 24, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment