不用IDE,而直接用命令编译JAVA包,仔细看了下,作一个记录。
以下的URL值得收藏。
http://www.aiuxian.com/article/p-2115485.html
http://www.cnblogs.com/haolujun/archive/2013/03/02/2939698.html
http://blog.sina.com.cn/s/blog_533074eb01014yd7.html
主要要理解classpath参数,d参数,及.作路径导向。
演示继承的四个文件如下:
Role.java
package cc.openhome; public class Role { private String name; private int level; private int blood; public int getBlood() { return blood; } public void setBlood(int blood) { this.blood = blood; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
SwordsMan.java
package cc.openhome; public class SwordsMan extends Role { public void fight() { System.out.println("Attack with swords"); } }
Magician.java
package cc.openhome; public class Magician extends Role { public void fight() { System.out.println("Attack with magician"); } }
RPG.java
package cc.openhome; public class RPG { public static void main(String[] args) { SwordsMan swordsMan = new SwordsMan(); swordsMan.setName("Justin"); swordsMan.setLevel(1); swordsMan.setBlood(200); System.out.printf("SwordsMan: (%s, %d, %d)%n", swordsMan.getName(), swordsMan.getLevel(), swordsMan.getBlood()); Magician magician = new Magician(); magician.setName("Monica"); magician.setLevel(2); magician.setBlood(100); System.out.printf("Magician: (%s, %d, %d)%n", magician.getName(), magician.getLevel(), magician.getBlood()); } }
目录结构平铺如下:
手动编译命令及执行顺序如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
时间: 2024-11-01 05:34:43