首页 > 代码库 > 米粉的构造方法和重载

米粉的构造方法和重载

public class Fen {
String mianma;
int liang;
boolean likesoup;
    
Fen(String m, int l, boolean s){
    mianma=m;
    liang=l;
    likesoup=s;
}

public Fen(String m, int l) {
    mianma=m;
    liang=l;
}

public void eat(String mianma,int liang,boolean likesoup){
    
}
public void eat(String mianma,int liang){
System.out.println(mianma+liang);
}
public void eat(String mianma){
System.out.println(mianma);
}
public void check(){
    System.out.println(mianma+liang+likesoup );
}




}
public class Test{
    public static void main(String[] args) {
Fen f=new Fen("牛肉", 2, false);
f.check();
f.eat("牛肉",3);
Fen f1=new Fen("酸辣", 2, true);
f1.check();

}

}

 

米粉的构造方法和重载