阅读背景:

在java中动态加载类

来源:互联网 

Here is my classes.

这是我的课程。

package com.psu.janibot;

public class Janibot implements Runnable {

    public void move() {
        System.out.println("move");
    }

    @Override
    public void run() {

    }

    // main method
    public static void main(String[] args) {
        try {
            Janibot janibot = (Janibot) Class.forName("Janitor").newInstance();
            janibot.run();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

import com.psu.janibot.Janibot;

public class Janitor extends Janibot {
    public void run() {
        move();
    }
}

package com.psu.janibot;

public class Janitor2 extends Janibot{
    public void run() {
        move();
    }
}
package com.psu



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: