满意答案
urzrke
2013.05.15
采纳率:55% 等级:12
已帮助:6697人
package com.a2000;public class TestWuMingFen {
private String theMa;
private int quantity;
private boolean likeSoup;
public TestWuMingFen(String theMa, int quantity, boolean likeSoup) {
super();
this.theMa = theMa;
this.quantity = quantity;
this.likeSoup = likeSoup;
}
public TestWuMingFen() {
this("酸辣", 2, true);
}
public TestWuMingFen(String theMa, int quantity) {
super();
this.theMa = theMa;
this.quantity = quantity;
}
public void check(){
if(likeSoup){
System.out.println(theMa+"酸辣"+" "+quantity+"两"+" 有汤");
}else System.out.println(theMa+"酸辣"+" "+quantity+"两"+" 没有汤");
}
}
package com.a2000;public class TestWuMingFen1 { public static void main(String[] args) {
TestWuMingFen t=new TestWuMingFen();
t.check();
TestWuMingFen f2 = new TestWuMingFen("牛肉",2);
f2.check();
}}
你试试 两个类。放、同一个包里。
11分享举报