Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
JavaCodeBasics/interf.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (46 sloc)
1.44 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |