package com.sanmao10;
import java.io.BufferedReader;
import java.io.FileReader;
public class test {
public static void main(String[] args) throws Exception{
BufferedReader buff=new BufferedReader(new FileReader("config.properties"));
Class c=Class.forName(buff.readLine());
Furits furits=(Furits)c.newInstance();//因为字节码文件是Apple所以 Furits furits=new Apple();
Juicer juicer=new Juicer(furits);
juicer.run();
}
}
package com.sanmao10;
public interface Furits {
public void Squeeze();
}
package com.sanmao10;
public class Juicer {
private Furits f;
public Juicer(){}
public Juicer(Furits f) {
this.f = f;
}
public void run(){
f.Squeeze();
}
}
package com.sanmao10;
public class Apple implements Furits{
@Override
public void Squeeze() {
System.out.println("苹果榨汁");
}
}
package com.sanmao10;
public class Orange implements Furits{
@Override
public void Squeeze() {
System.out.println("橘子榨汁");
}
}
com.sanmao10.Apple 配置文件内容