Penggunaan Superclass dan Subclass dalam Java

SUPERCLASS :

class SuperClass {

public void Vitamin() {

System.out.println(“Contoh Macam-macam Vitamin :”);

System.out.println(“- Vitamin A”);

System.out.println(“- Vitamin B1”);

System.out.println(“- Vitamin C”);

System.out.println(“- Vitamin D”);

System.out.println(“- Vitamin E”);

System.out.println(“- Vitamin K”);

}

public static void main(String[] args) {

SuperClass sc = new SuperClass();

sc.Vitamin();

}

}

OUTPUT

Contoh Macam-macam Vitamin :

– Vitamin A

– Vitamin B1

– Vitamin C

– Vitamin D

– Vitamin E

– Vitamin K

SUBCLASS :

class SubClass extends SuperClass {

public void Panggil() {

super.Vitamin();

System.out.println(” “);

System.out.println(“Sumber dan Akibat Kekurangan Vitamin :”);

}

public void VitaminA() {

System.out.println(“- Vitamin A”);

System.out.println(”  Sumber : wortel, pisang,pepaya, dll”);

System.out.println(”  Akibat kekurangan : rabun senja, katarak, dll”);

}

public void VitaminB1() {

System.out.println(“- Vitamin B1″);

System.out.println(”  Sumber : gandum, daging, susu, dll”);

System.out.println(”  Akibat Kekurangan : kulit kering, kulit bersisik, dll”);

}

public void VitaminC () {

System.out.println(“- Vitamin C”);

System.out.println(”  Sumber : jeruk, tomat, nanas, dll”);

System.out.println(”  Akibat Kekurangan : sariawan, gusi berdarah, dll”);

}

public void VitaminD() {

System.out.println(“- Vitamin D”);

System.out.println(”  Sumber : minyak ikan, telur, keju, dll”);

System.out.println(”  Akibat Kekurangan : gigi mudah rusak,” +

“pertumbuhan tulang tidak normal, dll”);

}

public void VitaminE() {

System.out.println(“- Vitamin E”);

System.out.println(”  Sumber : ikan, ayam, kuning telur, dll”);

System.out.println(”  Akibat Kekurangan : mandul, gangguan syaraf, dll”);

}

public void VitaminK() {

System.out.println(“- Vitamin K”);

System.out.println(”  Sumber : susu, sayuran segar, dll”);

System.out.println(”  Akibat Kekurangan : darah sulit membeku bila terluka, ” +

” pendarahan di dalam tubuh, dll”);

}

public static void main(String[]args) {

SubClass scs = new SubClass();

scs.Panggil();

scs.VitaminA();

scs.VitaminB1();

scs.VitaminC();

scs.VitaminD();

scs.VitaminE();

scs.VitaminK();

}

}

OUTPUT

Contoh Macam-macam Vitamin :

– Vitamin A

– Vitamin B1

– Vitamin C

– Vitamin D

– Vitamin E

– Vitamin K

Sumber dan Akibat Kekurangan Vitamin :

– Vitamin A

Sumber : wortel, pisang,pepaya, dll

Akibat kekurangan : rabun senja, katarak, dll

– Vitamin B1

Sumber : gandum, daging, susu, dll

Akibat Kekurangan : kulit kering, kulit bersisik, dll

– Vitamin C

Sumber : jeruk, tomat, nanas, dll

Akibat Kekurangan : sariawan, gusi berdarah, dll

– Vitamin D

Sumber : minyak ikan, telur, keju, dll

Akibat Kekurangan : gigi mudah rusak, pertumbuhan tulang tidak   normal, dll

– Vitamin E

Sumber : ikan, ayam, kuning telur, dll

Akibat Kekurangan : mandul, gangguan syaraf, dll

– Vitamin K

Sumber : susu, sayuran segar, dll

Akibat Kekurangan : darah sulit membeku bila terluka, pendarahan di dalam tubuh, dll

* Output Printscreen

Output Superclass

Output Superclass

Output Subclass

Output Subclass

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: