packagebiJiaoCheng;importjavax.swing.plaf.synth.SynthSeparatorUI;classTv{privateintsize;privateStringcolor;publicvoidguige(intsize,Stringcolor){System.out.print(this+"");...
package biJiaoCheng;
import javax.swing.plaf.synth.SynthSeparatorUI;
class Tv {
private int size;
private String color;
public void guige(int size, String color) {
System.out.print(this+" "); //就这里,this打印出来是哈希码,我想打印 "leShi"
this.size = size;
this.color = color;
}
void shengChan() {
System.out.print("大小:" + size + "寸" + " " + "颜色:" + color + " ");
if (this.size > 200 || this.size < 20) {
System.out.println("规格不符!");
} else {
System.out.println("可以生产");
}
}
}
public class ThisDuiXiang {
public static void main(String[] args) {
Tv leShi = new Tv();
leShi.guige(10, "black");
leShi.shengChan();
Tv kangJia = new Tv();
kangJia.guige(50, "red");
kangJia.shengChan();
}
}
打印结果:
biJiaoCheng.Tv@42ff665a 大小:10寸 颜色:black 规格不符!
biJiaoCheng.Tv@d98c113 大小:50寸 颜色:red 可以生产
想把biJiaoCheng.Tv@42ff665a是"leShi"
biJiaoCheng.Tv@d98c113是"kangJia"
展开