Selasa, 14 Agustus 2012
Demo Interface Turunan
interface IInduk {
double tambah(double a, double b);
double kurang(double a, double b);
}
interface ITurunan extends IInduk {
double kali(double a, double b);
double bagi(double a, double b);
}
class Aritmetika implements ITurunan {
private double x;
private double y;
Aritmetika(double x, double y) {
this.x = x;
this.y = y;
}
public double tambah(double a, double b) {
return (a + b);
}
public double kurang(double a, double b) {
return (a - b);
}
public double kali(double a, double b) {
return (a * b);
}
public double bagi(double a, double b) {
return (a / b);
}
public void cetakHasil() {
System.out.println("x = " + x);
System.out.println("y = " + y);
System.out.println();
System.out.println("x + y = " + tambah(x, y));
System.out.println("x - y = " + kurang(x, y));
System.out.println("x * y = " + kali(x, y));
System.out.println("x / y = " + bagi(x, y));
}
}
class DemoInterfaceTurunan {
public static void main(String[] args) {
// membuat objek Aritmetika dengan x=10.0 dan y=2.5
Aritmetika obj = new Aritmetika(10.0, 2.5);
obj.cetakHasil();
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar