daily pastebin goal
43%
SHARE
TWEET

Interface :)

Faria_Afrin Mar 13th, 2018 (edited) 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top