program encapsulation

Class Kokom

public class kokom {

private int x = 3;

protected int y = 8;

public void info()

{

System.out.println(“Diambil dari = ” + this.getClass().getName());

System.out.println(“x = ” + x);

System.out.println(“y = ” + y);

}

}

Class alpha

public class alpha extends kokom

{

private int z = 4;

public void info() {

System.out.println(“Dipanggil pada = ” + this.getClass().getName());

System.out.println(“y = “+y);

System.out.println(“z = “+z);

}

Class beta

public class beta {

public static void main(String[] args) {

kokom obj1 = new kokom();

obj1.info();

alpha obj2 = new alpha();

System.out.println(“”);

obj2.info();

}

}

 

Output :

init:

deps-jar:

compile-single:

run-single:

Diambil dari = kokom

x = 3

y = 8

 

Dipanggil pada = alpha

y = 8

z =

BUILD SUCCESSFUL (total time: 0 seconds)

 

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: