本帖最后由 李道福 于 2013-3-29 17:46 编辑
- interface Person{
- void show();
- void doing();
- }
- class Student implements Person{
- public void show(){
- System.out.println("你好,我是学生");
- }
- public void doing(){
- System.out.println("我正在看书");
- }
- }
- class Worker implements Person{
- public void show(){
- System.out.println("你好,我是工人");
- }
- public void doing(){
- System.out.println("我正在工作");
- }
- }
- class Teacher implements Person{
- public void show(){
- System.out.println("你好,我是老师");
- }
- public void doing(){
- System.out.println("我正在上课");
- }
- }
- class impFactory{
- public static Person factorys() throws InstantiationException, IllegalAccessException, ClassNotFoundException{
- Person p=(Person)Class.forName("Student").newInstance();
- return p;
- }
- }
- public class Factory {
- /**
- * @param args
- * @throws ClassNotFoundException
- * @throws IllegalAccessException
- * @throws InstantiationException
- */
- public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
- Person p=impFactory.factorys();
- p.show();
- p.doing();
- }
- }
- 为什么这些代码在DOS命令行中能通过编译正常运行,而在MyEclipse中却不能通过编译,报出ClassNotFoundException异常?
复制代码 |