Advertisement
Faria_Afrin

Interface :)

Mar 13th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. public interface Animal
  2. {
  3.     public void eat();
  4.     public void run();
  5.    
  6. }
  7. public class Dog implements Animal {
  8.  
  9.    
  10.     public void eat() {
  11.      
  12.         System.out.println("\nDog eats meat.");
  13.        
  14.     }
  15.  
  16.     public void run() {
  17.        
  18.         System.out.println("Dog can run.");
  19.        
  20.     }
  21.  
  22. }
  23. public class Cat implements Animal {
  24.  
  25.    
  26.     public void eat() {
  27.      
  28.         System.out.println("Cat eats meat.");
  29.        
  30.     }
  31.  
  32.     public void run() {
  33.        
  34.         System.out.println("Cat can run.");
  35.        
  36.     }
  37.    
  38.          
  39.     }
  40. public class Main {
  41.  
  42.     public static void main(String[] args) {
  43.          
  44.                 Animal c1 = new Cat();
  45.                
  46.                 Animal d2 = new Dog();
  47.                
  48.                 c1.eat();
  49.                 c1.run();
  50.                 d2.eat();
  51.                 d2.run();
  52.  
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement