Selasa, 14 Agustus 2012
Program Turunan Bertingkat
class A {
private int a;
public void setA(int nilai) {
a = nilai;
}
public int getA() {
return a;
}
}
class B extends A {
private int b;
public void setB(int nilai) {
b = nilai;
}
public int getB() {
return b;
}
}
class C extends B {
private int c;
public void setC(int nilai) {
c = nilai;
}
public int getC() {
return c;
}
}
class D extends C {
private int d;
public void setD(int nilai) {
d = nilai;
}
public int getD() {
return d;
}
}
class DemoTurunanBertingkat {
public static void main(String[] args) {
// membentuk objek dari kelas D
D obj = new D();
// mengisi nilai
obj.setA(10);
obj.setB(20);
obj.setC(30);
obj.setD(40);
// menampilkan nilai
System.out.println("Nilai a : " + obj.getA());
System.out.println("Nilai b : " + obj.getB());
System.out.println("Nilai c : " + obj.getC());
System.out.println("Nilai d : " + obj.getD());
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar