java MyEclipse 提示Type mismatch: cannot convert from int to String
下面是超类源代码packageboat;publicclassBoat{privateStringstateNo;privatedoublelength;privateS...
下面是超类源代码
package boat;
public class Boat {
private String stateNo;
private double length;
private String facturer;
private int year;
public Boat(String astateNo,double alength,String afacturer,int ayear)
{setstateNo(astateNo);
setlength(alength);
setfacturer(afacturer);
setyear(ayear);}
public void setstateNo(String astateNo)
{stateNo=astateNo;}
public void setlength(double alength)
{length=alength;}
public void setfacturer(String afacturer)
{facturer=afacturer;}
public void setyear(int ayear)
{year=ayear;}
public String getstateNo()
{return stateNo;}
public double getlength()
{return length;}
public String getfacturer()
{return facturer;}
public int getyear()
{return year;}}
下面是powerboat类
package boat;
public class Sailboat extends Boat{
private double keelDepth;
private int noSails;
private String motorType;
public Sailboat(String astateNo,double alength,String afacturer,int ayear,
double akeelDepth,int anosails,String amotorType)
{super(astateNo,alength,afacturer,ayear);
setkeelDepth(akeelDepth);
setnoSails(anosails);
setmotorType(amotorType);}
public void setkeelDepth(double akeelDepth)
{keelDepth=akeelDepth;}
public void setnoSails(int anosails)
{noSails=anosails;}
public void setmotorType(String amotorType)
{motorType=amotorType;}
public double getkeelDepth()
{return keelDepth;}
public int getnoSails()
{return noSails;}
public String getmotorType()
{return motorType;}
}
下面是有错误的test类(部分)
{Sailboat fb=new Sailboat("mo123456",28,"tartan",1998,4.11,2,"inboard"); 展开
package boat;
public class Boat {
private String stateNo;
private double length;
private String facturer;
private int year;
public Boat(String astateNo,double alength,String afacturer,int ayear)
{setstateNo(astateNo);
setlength(alength);
setfacturer(afacturer);
setyear(ayear);}
public void setstateNo(String astateNo)
{stateNo=astateNo;}
public void setlength(double alength)
{length=alength;}
public void setfacturer(String afacturer)
{facturer=afacturer;}
public void setyear(int ayear)
{year=ayear;}
public String getstateNo()
{return stateNo;}
public double getlength()
{return length;}
public String getfacturer()
{return facturer;}
public int getyear()
{return year;}}
下面是powerboat类
package boat;
public class Sailboat extends Boat{
private double keelDepth;
private int noSails;
private String motorType;
public Sailboat(String astateNo,double alength,String afacturer,int ayear,
double akeelDepth,int anosails,String amotorType)
{super(astateNo,alength,afacturer,ayear);
setkeelDepth(akeelDepth);
setnoSails(anosails);
setmotorType(amotorType);}
public void setkeelDepth(double akeelDepth)
{keelDepth=akeelDepth;}
public void setnoSails(int anosails)
{noSails=anosails;}
public void setmotorType(String amotorType)
{motorType=amotorType;}
public double getkeelDepth()
{return keelDepth;}
public int getnoSails()
{return noSails;}
public String getmotorType()
{return motorType;}
}
下面是有错误的test类(部分)
{Sailboat fb=new Sailboat("mo123456",28,"tartan",1998,4.11,2,"inboard"); 展开
4个回答
展开全部
两者的结构类型不一致,不可强制赋值,可以先实现转化类型
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-11-25
展开全部
不是告诉你错误了,不能把int转换成String,你还要转?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
年月日为什么要用double和int?从没见过这么处理的,都是传日期字符串,然后处理字符串。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询