Presentation is loading. Please wait.

Presentation is loading. Please wait.

Abstract Class, Interface, Package

Similar presentations


Presentation on theme: "Abstract Class, Interface, Package"— 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 <<abstract>>
Animal <<abstract>> Dog Cat Bird Bat Interface : Flyer Interface : Speaker

4 Class Animal public abstract class Animal { private int age; public void setAge(int newAge) this.age=newAge; } public int getAge() 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; public void eat() { System.out.println(name+" eat fish"); 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 Lengkapi pada project di atas
Interface Speaker Class Dog Class Bird Class Bat


Download ppt "Abstract Class, Interface, Package"

Similar presentations


Ads by Google