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"
java中怎么将对象名让类中添加打印
答案:3 悬赏:0 手机版
解决时间 2021-01-29 18:42
- 提问者网友:献世佛
- 2021-01-29 11:38
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-01-29 12:57
package biJiaoCheng;
import javax.swing.plaf.synth.SynthSeparatorUI;
class Tv {
private String brand;
private int size;
private String color;
public void guige(String brand, int size, String color) {
this.brand = brand;
System.out.print(this.brand+" "); //就这里,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("leShi",10, "black");
leShi.shengChan();
Tv kangJia = new Tv();
kangJia.guige("kangJia",50, "red");
kangJia.shengChan();
}
}
import javax.swing.plaf.synth.SynthSeparatorUI;
class Tv {
private String brand;
private int size;
private String color;
public void guige(String brand, int size, String color) {
this.brand = brand;
System.out.print(this.brand+" "); //就这里,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("leShi",10, "black");
leShi.shengChan();
Tv kangJia = new Tv();
kangJia.guige("kangJia",50, "red");
kangJia.shengChan();
}
}
全部回答
- 1楼网友:佘樂
- 2021-01-29 14:40
楼主,覆盖 public String toString() 方法
- 2楼网友:行路难
- 2021-01-29 13:37
import java.awt.*;
import java.swing.*;
class mymenu extends menu {
public mymenu() {
}
public mymenu(//传参数) {
//写相应的构造方法
}
}
class myframe extends frame {
private mymenu mm = null;
public myframe() {
}
public myframe(mymenu mm) {
this.mm = mm;
}
public void launchframe() {
///写frame的方法
}
}
public class testmenu {
public static void main(string[] args) {
new myframe(//传参).launchframe();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯