1 / 8

Abstract Class, Interface, Package

Abstract Class, Interface, Package. Membuat sebuah project yang mengimplementasikan interface dan abstract class, dengan rincian sbb Abstract Class Animal Interface Flyer Interface Speaker Class Dog : extends Animal and implements Speaker Class Cat : extends Animal and implements Speaker

dixie
Télécharger la présentation

Abstract Class, Interface, Package

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Abstract Class, Interface, Package

  2. Membuat sebuah project yang mengimplementasikan interface dan abstract class, dengan rincian sbb • Abstract Class Animal • Interface Flyer • Interface Speaker • Class Dog : extends Animal and implements Speaker • Class Cat : extends Animal and implements Speaker • Class Bird : extends Animal and implements Speaker, Flyer • Class Bat : extends Animal and implements Flyer • Main.java (main class)

  3. Animal <<abstract>> Dog Cat Bird Bat Interface : Flyer Interface : Speaker

  4. Class Animal public abstract class Animal { private int age; public void setAge(intnewAge) { this.age=newAge; } public intgetAge() { return age; } public abstract void eat() ; public abstract void walk(); }

  5. Interface Flyer public interface Flyer { public void flying(); }

  6. Class Cat public class Cat extends Animal implements Speaker { String name; public Cat(String newName) { this.name=newName; } @Override public void eat() { System.out.println(name+" eat fish"); } @Override public void walk() { System.out.println(name+" with four leg"); } public void speaking() { System.out.println(name+" speaks MIAUW MIAUW"); } }

  7. Class Main public class Main{ public static void main(String[] args) { Cat caty=new Cat("Caty"); caty.setAge(2); System.out.println("Caty's age is "+caty.getAge()+" years "); caty.eat(); caty.speaking(); } }

  8. Lengkapipada project diatas • Interface Speaker • Class Dog • Class Bird • Class Bat

More Related