RSS Feed

Tugas ke-dua PBO

Tugas PBO yang ke-dua ini adalah mengenai contoh dari information hiding, encapsulation dan inheritance atau pewarisan.


1. Superclass dan Subclass

class hewan {
public void methodAwal() {
system.out.println(“Action superclass: “);
system.out.println(“a. Berjalan”);
system.out.println(“b. Bernafas”);
public static void main(string[] args) {
hewan oks = new hewan();


Action superclass:
a. Berjalan
b. Bernafas



class hewanBersayap extends hewan {
public void methodPemanggil() {
public void methodNama() {
system.out.println(“Subclass: Hewan bersayap “);
system.out.println(“a. Angsa”);
system.out.println(“b. Capung”);
public void methodJmlsayap() {
system.out.println(“Jumlah sayap:”);
system.out.println(“a. Satu pasang”);
system.out.println(“b. Dua pasang”);
public static void main(String[] args) {
hewanBersayap oks = new hewanBersayap();

Subclass: Hewan bersayap
a. Angsa
b. Capung
Jumlah sayap:
a. Satu pasang
b. Dua pasang


2. Information hiding dan Encapsulation

public class persegi {
private double sisi;
public persegi() {
private double luas(double s) {
return s*s;
public void setSisi(double sisi) {
public double getSisi() {
return sisi;
public double getLuas() {
return luas(sisi);

public class mainPersegi {
public static void main(string[] args) {
persegi pp = new persegi();
pp.setSisi (15);
system.out.println(“Sisi = “+ pp.getSisi());
system.out.println(“Luas = “+ pp.getLuas());

Sisi = 15.0
Luas = 225.0

yuniarty utami

About Yuniarty Utami

Yuniarty Utami is a student of Information System, Faculty of Computer Science and Information Technology, Gunadarma University.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: