Leemaasn(我给大家拜早年啦!新春快乐!!!)
你到处UP啊:??三版?看的是英文的??
你到处UP啊:??三版?看的是英文的??
解决方案 »
- jfreechart出错: Can't create cache file!
- 如何把int数组里面的元素转成String?
- 如何在JTable中实现数据的增删改查,有示例说明最好
- 多个Timer任务 怎么同事访问同一个static 类中的属性
- java如何获取class文件所在本机路径,非URL
- 如何定义一个含有小数的数组
- Tomcat JSP的一个奇怪的问题
- 不算复杂但很麻烦的JAVA编译和运行如何通过鼠标右键来实现???
- 如何 把一个JFrame 在一被打开的时候 变成全屏显示?
- jb7+wl7和win2000+sp3编译时出现outofmemory的问题
- jdbc getconnection()没有反应?
- 怎么用JAVA开发一个简单应用程序?
class FruitQualities {
private int weight;
private int color;
private int firmness;
private int ripeness;
private int smell;
/* Default constructor */
public FruitQualities() {
}
/* Copy constructor */
public FruitQualities(FruitQualities f) {
weight = f.weight;
color = f.color;
firmness = f.firmness;
ripeness = f.ripeness;
smell = f.smell;
}
}
class Seed {
public Seed() { /* Default constructor */
}
public Seed(Seed s) { /* Copy constructor */
}
}
class Fruit {
private FruitQualities fq;
private int seeds;
private Seed[] s;
public Fruit(FruitQualities q, int seedCount) {
fq = q;
seeds = seedCount;
s = new Seed[seeds];
for (int i = 0; i < seeds; i++)
s[i] = new Seed();
}
// Copy constructor:
public Fruit(Fruit f) {
fq = new FruitQualities(f.fq);
seeds = f.seeds;
s = new Seed[seeds];
// Call all Seed copy-constructors:
for (int i = 0; i < seeds; i++)
s[i] = new Seed(f.s[i]);
}
}
class Tomato extends Fruit {
public Tomato() {
super(new FruitQualities(), 100);
}
public Tomato(Tomato t) { // Copy-constructor
super(t); // Upcast for base copy-constructor
// Other copy-construction activities...
}
}
public class B { public static void ripen(Tomato t) {
// Use the "copy constructor":
t = new Tomato(t);
System.out.println("In ripen, t is a " + t.getClass().getName());
}
public static void slice(Fruit f) {
f = new Fruit(f); // Hmmm... will this work?
System.out.println("In slice, f is a " + f.getClass().getName());
}
public static void main(String[] args) {
Tomato tomato = new Tomato();
ripen(tomato); // OK
slice(tomato); // OOPS!
}
} ///:~
class FruitQualities {
private int weight;
public FruitQualities() {}/* Default constructor */
public FruitQualities(FruitQualities f) {
weight = f.weight;/* Copy constructor */}
}
class Seed {
public Seed() { /* Default constructor */}
public Seed(Seed s) { /* Copy constructor */}
}
class Fruit {
private FruitQualities fq;
private int seeds;
private Seed[] s;
public Fruit(FruitQualities q, int seedCount) {
fq = q;
seeds = seedCount;
s = new Seed[seeds];
for (int i = 0; i < seeds; i++)
s[i] = new Seed();}
// Copy constructor:
public Fruit(Fruit f) {
fq = new FruitQualities(f.fq);
seeds = f.seeds;
s = new Seed[seeds];
// Call all Seed copy-constructors:
for (int i = 0; i < seeds; i++)
s[i] = new Seed(f.s[i]);}
}
class Tomato extends Fruit {
public Tomato() {
super(new FruitQualities(), 100);}
public Tomato(Tomato t) { // Copy-constructor
super(t); // Upcast for base copy-constructor}
}
public class B {
public static void ripen(Tomato t) {
// Use the "copy constructor":
t = new Tomato(t);
System.out.println("In ripen, t is a " + t.getClass().getName());
}
public static void slice(Fruit f) {
f = new Fruit(f); // Hmmm... will this work?
System.out.println("In slice, f is a " + f.getClass().getName());
}
public static void main(String[] args) {
Tomato tomato = new Tomato();
ripen(tomato); // OK
slice(tomato); // OOPS!}
}