Inheritance (Implements)

Lesson 35
Author : Afrixi
Last Updated : October, 2017


Java - Programming Language
This course covers the basics of programming in Java. Work your way through the videos/articles and I'll teach you everything you need to know to start your programming journey!
Table of Content

Code

Copyinterface Animal{
     public void speak();
}

class Cat implements Animal{
     @Override
     public void speak(){
          System.out.println("Meow Meow");
     }
}

class Dog implements Animal{
     @Override
     public void speak(){
          System.out.println("Woof Woof");
     }
}

public class App{
     public static void main(String [] args){
          Animal [] animals = {
               new Dog(),
               new Cat()
          };
          for(Animal animal : animals){
               animal.speak();
          }     
     }
}