一样的代码,下面怎么就不兼容呢?public class Item { String name; int price; public static void main(String[] args) { Item potion = new Item(); potion.name= "血瓶"; potion.price =50; Item shoe = new Item(); shoe.name= "草鞋"; shoe.price =300; Item sword = new Item(); sword.name= "长剑"; sword.price =350; }}public class Item{ String name; //名字 int price; //价格 public static void main(String[]args){ Item xuepin = new Item(); xuepin.name = "血瓶"; xuepin.price = "50"; Item caoxie = new Item(); caoxie.name = "草鞋"; caoxie.price = 300; Item changjian = new Item(); changjian.name = "长剑"; changjian.price = "350"; } } 不兼容的类型: String无法转换为int xuepin.price = "50"; ^Item.java:17: 错误: 不兼容的类型: String无法转换为int changjian.price = "350";
添加回答
举报
0/150
提交
取消