62,621
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
public class DirList {
public static void main(String[] args) {
File path = new File(
DirList.class.getResource(".").getFile().toString()
);
System.out.println(
DirList.class.getResource(".").getFile().toString()
);
}
}
import java.io.*;
public class DirList {
public static void main(String[] args) {
File path = new File(
DirList.class.getResource(".").getFile().toString()
);
System.out.println(
DirList.getClass().getResource(".").getFile().toString()
);
}
}
Abstract class Animal {
protected Logger logger = LoggerFacotry.getLogger(getClass());
...
}
Cat extends Animal {
Cat () {
}
}
interface IAnimal {
String whoAmI();
}
class Cat implements IAnimal {
@Override
public String whoAmI() {
return "I am " + Cat.class;
}
}
class Dog implements IAnimal {
@Override
public String whoAmI() {
return "I am " + Dog.class;
}
}
class AnimalTest {
public static void main (final String[] args) {
IAnimal animal1 = new Cat();
IAnimal animal2 = new Dog();
tellMeWho(animal1);
tellMeWho(animal2);
System.out.println(animal1.whoAmI());
System.out.println(animal2.whoAmI());
}
private static void tellMeWho(IAnimal animal) {
System.out.println("I am " + animal.getClass());
}
}
读完代码你就懂了。这是两种应用场景