Contoh Abstract dalam java sederhana


disini saya mempunyai class manusia yang mempunya turunan, cekidot lsg source codenya

class mutant

</strong>

package manusia;

&nbsp;

/**

*

* @author tiano89

*/

public class Mutant extends Manusia {

&nbsp;

@Override

public void bersuara() {

System.out.println("Menggeram");

}

&nbsp;

@Override

public void bergerak() {

System.out.println("jalan dengan cepat dan hati-hati");

}
<div>

}

</div>
<strong>

class orang

</strong>

<strong>Class Orang</strong>

package manusia;

&nbsp;

/**

*

* @author tiano89

*/

public class Orang extends Manusia {

String gerak;

String suara;

@Override

public void bersuara() {

System.out.println("Normal");

}

&nbsp;

@Override

public void bergerak() {

System.out.println("Jalan Biasa");

}

<strong>

</strong>

package manusia;

&nbsp;

/**

*

* @author Seftian Setia P-10108409

*/

public abstract class  Manusia {

&nbsp;

static void judul()

{

System.out.println(".....Kelas Manusia.....");

}

public abstract void bersuara();

public abstract void bergerak();

public static void main(String[] args) {

judul();

System.out.println("---Orang---");

Manusia m = new Orang();

m.bergerak();

m.bersuara();

System.out.println("---Mutant---");

Manusia t = new Mutant();

t.bergerak();

t.bersuara();

}
<div>

    }

</div>
<strong>

silahkan di coba😉

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