RSS Feed

Tugas ke-tiga PBO

Abstract Class dan Interface

abstract class Hewan{

protected String nama;
protected int jmlSayap;
public Hewan(String nama, int sayap){
this.nama=nama;
jmlSayap=sayap;
}

public abstract void bernyanyi();
public static void berdansa(){
}

public void isHewan(){
System.out.println(“Nama: ”+nama);
System.out.println(“Jumlah sayap: ”+jmlSayap);
}
}

interface Manusia{
public void bernyanyi();
public void tertawa();
}

class Pipingu extends Hewan implements Manusia{
public Pipingu(){
super(“Pipingu”,2);
}

public void bernyanyi(){
System.out.println(“\nPenguin, penguin flap your little wings!”);
}

public void tertawa(){
System.out.println(“Hahaha..!”);
}

public static void berdansa(){
System.out.println(“Let’s dance with me.. Pingu dance, woohoo..!”);
public static void main(String[] args){
Pipingu a = new Pipingu();
a.isHewan();
a.bernyanyi();
a.tertawa();
a.berdansa();
}
}

utami
yuniarty

Output:
Nama : Pipingu
Jumlah sayap : 2
Penguin, penguin flap your little wings!
Hahaha..!
Let’s dance with me.. Pingu dance, woohoo..!

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:

WordPress.com Logo

You are commenting using your WordPress.com 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: