Tuesday, November 17, 2015
INHERITANCE
oke pada kesempatan ini saya akan post tentang penurunan (inheritance) pada pemrograman java
langsung ajah ya
/**
My Task 20 Mei 2015 java program
Author : Desi Angraeni Siregar :)
*/
public abstract class Hewan{
protected String name;
public Hewan (String name){
this.name=name;
}
public String getName(){
return this.name;
}
public abstract void bersuara();
}
dan ini bentuk tampilannya
/**
My Task 20 Mei 2015 java program
Author : Desi Angraeni Siregar :)
*/
class Kucing extends Hewan {
public Kucing (String name){
super(name);
}
public void bersuara(){
System.out.println("Kucing " + super.getName()+" mengeong...");
}
}
class Anjing extends Hewan {
public Anjing (String name){
super(name);
}
public void bersuara(){
System.out.println("Anjing " + super.getName()+" menggonggong...");
}
}
class Harimau extends Hewan {
public Harimau (String name){
super(name);
}
public void bersuara(){
System.out.println("Harimau " + super.getName()+" mengaum...");
}
}
class Ular extends Hewan {
public Ular (String name){
super(name);
}
public void bersuara(){
System.out.println("Ular " + super.getName()+" mendesis...");
}
}
class Ayam extends Hewan {
public Ayam (String name){
super(name);
}
public void bersuara(){
System.out.println("Ayam " + super.getName()+" berkotek...");
}
}
class Lembu extends Hewan {
public Lembu (String name){
super(name);
}
public void bersuara(){
System.out.println("Lembu " + super.getName()+" melenguh...");
}
}
class Tikus extends Hewan {
public Tikus (String name){
super(name);
}
public void bersuara(){
System.out.println("Tikus " + super.getName()+" mencicit...");
}
}
class Kambing extends Hewan {
public Kambing (String name){
super(name);
}
public void bersuara(){
System.out.println("Kambing " + super.getName()+" Mengembek...");
}
}
public class AbstractHewan{
public static void main(String args[]){
Kucing anggora = new Kucing("Anggora");
anggora.bersuara();
Anjing herder = new Anjing("Herder");
herder.bersuara();
Harimau tutul = new Harimau("Tutul");
tutul.bersuara();
Ular cobra = new Ular("Cobra");
cobra.bersuara();
Ayam hutan = new Ayam("Hutan");
hutan.bersuara();
Lembu thailand = new Lembu("Thailand");
thailand.bersuara();
Tikus sawah = new Tikus("Sawah");
sawah.bersuara();
Kambing biri_biri = new Kambing("Biri-biri");
biri_biri.bersuara();
}
}
jangan lupa komentarnya ya gan sis
Siregarinfo
Author & Editor
Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.
November 17, 2015
KOMPUTER DAN INTERNET
Subscribe to:
Post Comments (Atom)
Lucky Club: The best online casino site for you to play slots
ReplyDeleteof this site is a unique online casino site luckyclub.live that uses the technology of the internet and the fact that all users are online is absolutely safe.