inf : http://www.tutorialspoint.com/java/java_packages.htm
1. the interface method cannot have body.
2. when implements the implements must after extends.
You and other programmers can easily determine that these types are related.
/* File name : Animal.java */
package animals;
interface Animal {
public void eat();
public void travel();
}
/* File name : MammalInt.java */
package animals;
public class MammalInt implements Animal{
public void eat(){
System.out.println("Mammal eats");
}
public void travel(){
System.out.println("Mammal travels");
}
public int noOfLegs(){
return 0;
}
public static void main(String args[]){
MammalInt m = new MammalInt();
m.eat();
m.travel();
}
}
$ mkdir animals
$ javac Animal.java
$ javac MammalInt.java
$ cp Animal.class animals
$ cp MammalInt.class animals
$ java animals/MammalInt
Mammal eats
Mammal travels
but
cd animals
java MammalInt fail
沒有留言:
張貼留言