Rabu, 05 Desember 2012

Contoh Sifat Akses Pada JAVA (Protected)


import java.io.*;
class Soal3 {
protected int a,b,c;
public Soal3() { a=3; b=5; c=7; }
public int fungsi1 () {return (a+b-c); }
public void fungsi11() {
if (a>b)
System.out.println("Mengecek a dan b");
else if (b>c)
System.out.println("Mengecek b dan c");
else
System.out.println("Mengecek a dan c");
}
}

class Soal2 extends Soal3 {
public int fungsi2() {return (c%2); }
public void fungsi21() {
for (int i=1;i<b;i++)
c=c-a;
System.out.println("Output 1= "+c);
}
}


public class Soal1{
public static void main (String[] args) {

Soal3 a=new Soal3();
Soal2 b=new Soal2();
a.fungsi11();
b.fungsi11();
System.out.println("Output 2 = "+a.fungsi1());
System.out.println("Output 3 = "+b.fungsi1());
b.fungsi21();
System.out.println("Output 4 = "+b.fungsi2());

}
}

0 komentar:

Posting Komentar