Skip to content
Permalink
Browse files
interfaces
Using Interfaces and Inner classes in java
  • Loading branch information
sareenv committed Feb 8, 2019
1 parent ff60404 commit 3fd923499b4c0e0570efec2267de8c93477b41bf
Showing 1 changed file with 60 additions and 0 deletions.
@@ -0,0 +1,60 @@
public class JavaApplication1 {

/**
*/

// Interface just contains the definations that needs to be implemented whoever
// conforms to the Animal interface - It's like a basketball coach who doesn't know
// how to play but can teach other about it.
public interface Animal{
public String eat();
public void run();
public void jump();
}


public class ZooAnimals implements Animal{

public String eat;
public String run;
public String jump;

// This is a constructure method.
public ZooAnimals(String eat, String run, String jump){
this.eat = eat;
this.jump = jump;
this.run = run;
}

@Override
public String eat() {
return this.eat;
}

@Override
public void run() {
System.out.println(this.run);
}

@Override
public void jump() {
System.out.println(this.jump);
}

}

public void animalInformation(){
ZooAnimals x;
x = new ZooAnimals("Eat fresh", "Can run fast", "Cannot jump high");
String result = x.eat();
System.out.println(result);
}

public static void main(String[] args) {
// TODO code application logic here
JavaApplication1 j1 = new JavaApplication1();
j1.animalInformation();

}

}

0 comments on commit 3fd9234

Please sign in to comment.