Anisafitriana89's Blog
Just another WordPress.com weblog

Tugas Java 3

Program Abstract Class dan Interface

abstract class Animal{
protected String nama;
protected int jumKaki;
public Animal(String nama, int kaki){
this.nama=nama;
jumKaki=kaki;
}
public abstract void bersuara();
public static void makan(){
}
public void isAnimal(){
System.out.println(“nama :”+nama);
System.out.println(“jumlah kaki :”+jumKaki);
}
}
interface Human{
public void bersuara();
public void ketawa();
}
class Doraemon extends Animal implements Human{
public Doraemon(){
super(“Doraemon”,4);
}
public void bersuara(){
System.out.println(“\nWuaaahhh,,ada kue Dorayakiii…!!”);
}
public void ketawa(){
System.out.println(“Hahahahahahaha..”);
}
public static void makan(){
System.out.println(“nyam..nyam..nyam..enak..”);
public static void main(String[] args){
Doraemon a = new Doraemon();
a.isAnimal();
a.bersuara();
a.ketawa();
a.makan();
}
}

Output :
nama : Doraemon
jumlah kaki :4

Wuaaahhh,,ada kue Dorayakiii…!!
Hahahahahahaha..
nyam..nyam..nyam..enak..

No Responses to “Tugas Java 3”

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: