本视频是解读性视频,所以希望您已经看过了本知识点的内容,并且编写了相应的代码之后,带着疑问来观看,这样收获才多。 不建议一开始就观看视频
![]() 7分55秒 本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器 步骤 1 : 设计英雄这个类 步骤 2 : 创建具体的英雄 步骤 3 : 类的第一个字母大写 步骤 4 : 练习-Item 步骤 5 : 答案-Item public class Hero {
String name; //姓名
float hp; //血量
float armor; //护甲
int moveSpeed; //移动速度
}
public class Hero { String name; //姓名 float hp; //血量 float armor; //护甲 int moveSpeed; //移动速度 }
类就像一个模板,根据这样一个模板,可以创建一个个的具体的英雄
一个个具体的英雄,就叫一个个的对象 new Hero() 就是java中创建一个英雄对象的意思 public class Hero {
String name; //姓名
float hp; //血量
float armor; //护甲
int moveSpeed; //移动速度
public static void main(String[] args) {
Hero garen = new Hero();
garen.name = "盖伦";
garen.hp = 616.28f;
garen.armor = 27.536f;
garen.moveSpeed = 350;
Hero teemo = new Hero();
teemo.name = "提莫";
teemo.hp = 383f;
teemo.armor = 14f;
teemo.moveSpeed = 330;
}
}
好的编程习惯会让代码看上去更清爽,易读,容易维护
比如类的第一个字母大写 Hero public class Hero {
}
public class Hero { }
设计出物品这种类
类名:Item 物品有如下属性: 名字 name 类型是字符串String 价格 price 类型是整型 int 创建(实例化)3件具体物品 名称 价格 血瓶 50 草鞋 300 长剑 350
在查看答案前,尽量先自己完成,碰到问题再来查看答案,收获会更多
本视频是解读性视频,所以希望您已经看过了本答案的内容,带着疑问来观看,这样收获才多。 不建议一开始就观看视频
![]() 2分16秒 本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器
注: 创建Item这个类的时候,必须写在一个Item.java的文件里,不可以使用其他文件名,大小写也要保持一致,不能是item.java
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 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; } }
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
![]()
问答区域
2022-11-15
Hero无法解析为类型怎么解决
17 个答案
lu010118 跳转到问题位置 答案时间:2023-03-20 public class Item {
String name;
int price;
public static void main(String[] args) {
Item xueping=new Item();
xueping.name="血瓶";
xueping.price=50;
Item caoxie=new Item();
caoxie.name="草鞋";
caoxie.price=300;
Item changjian=new Item();
changjian.name="长剑";
changjian.price=350;
}
}
yslkl20170615 跳转到问题位置 答案时间:2023-03-13 yslkl20170615 跳转到问题位置 答案时间:2023-03-13 怪异的羊 跳转到问题位置 答案时间:2023-02-25 出招非我愿 跳转到问题位置 答案时间:2023-02-13
public class Item {
String name;
int price;
public static void main(String[] args) {
Item xueping = new Item();
xueping.name = "血瓶";
xueping.price = 50;
Item caoxie = new Item();
caoxie.name = "草鞋";
caoxie.price = 300;
Item changjian = new Item();
changjian.name = "长剑";
changjian.price = 350;
}
}
isNpy 跳转到问题位置 答案时间:2023-02-08 代号9527 跳转到问题位置 答案时间:2023-01-31 public class Item {
String name;
int price;
public static void main(String[] args) {
Item test1 = new Item();
test1.name = "血瓶";
test1.price = 50;
Item test2 = new Item();
test2.name = "草鞋";
test2.price = 300;
Item test3 = new Item();
test3.name = "长剑";
test3.price = 350;
System.out.println("物品名称"+"\t"+"物品价格");
System.out.println(test1.name+"\t\t"+test1.price);
System.out.println(test2.name+"\t\t"+test2.price);
System.out.println(test3.name+"\t\t"+test3.price);
}
}
javaPlayer 跳转到问题位置 答案时间:2023-01-03 学习使我快乐999 跳转到问题位置 答案时间:2022-12-27 package java.javase.javase-demo.面向对象;
public class mianixangduixiang {
String name;//名称
int price;//价格
String effect;//作用
public static void main (String[]args){
mianixangduixiang xueping=new mianixangduixiang();//创建了血瓶
xueping.name="血瓶";
xueping.price=50;
xueping.effect="回复血量100hp";
mianixangduixiang caoxie=new mianixangduixiang();
caoxie.name="草鞋";
caoxie.price=300;
caoxie.effect="增加移动速度30";
mianixangduixiang changjian=new mianixangduixiang();
changjian.name="长剑";
changjian.price=500;
changjian.effect="增加攻击力10";
System.out.println();
}
莫諾 跳转到问题位置 答案时间:2022-12-26 练习-Item
创建(实例化)3件具体物品
名称 价格
血瓶 50
草鞋 300
长剑 350
Bingod 跳转到问题位置 答案时间:2022-12-22 天亮讲晚安 跳转到问题位置 答案时间:2022-12-20 M156427895 跳转到问题位置 答案时间:2022-12-11 package xu;
public class Item {
String name;//物品名字
int price;//物品价格
public static void main(String[] args) {
Item xuping =new Item();
xuping.name="血瓶";
xuping.price=50;
Item caoxie =new Item();
caoxie.name="草鞋";
caoxie.price=300;
Item changjian =new Item();
changjian.name="长剑";
changjian.price=350;
System.out.println("第一件物品:"+xuping.name+xuping.price+"元");
System.out.println("第二件物品:"+ caoxie.name+caoxie.price+"元");
System.out.println("第三件物品:"+changjian.name+changjian.price+"元");
}//end main
}//end Item
猿某人 跳转到问题位置 答案时间:2022-12-09 public class Item {
String name;
int price;
public static void main(String[] args){
Item xueping=new Item();
xueping.name="血瓶";
xueping.price=50;
Item caoxie=new Item();
caoxie.name="草鞋";
caoxie.price=300;
Item changjian=new Item();
changjian.name="长剑";
changjian.price=350;
}
}
巴特 跳转到问题位置 答案时间:2022-12-06 Hero是一个类,你没有编这个类
类用class修饰
public class是主类
你编的是low主类里面的字段,
并没有编Hero类
胖水龙 跳转到问题位置 答案时间:2022-11-21 itniko 跳转到问题位置 答案时间:2022-11-18 public class Item{
String name;
Int price;
}
pbulic 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;
}
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2022-09-23
代码
14 个答案
怪异的羊 跳转到问题位置 答案时间:2023-02-23 添加了构造方法,如果考试,我肯定按照题目要求来
jiangnanyis 跳转到问题位置 答案时间:2023-02-01 HBong 跳转到问题位置 答案时间:2023-01-29 左耳进右耳出 跳转到问题位置 答案时间:2023-01-06 public class Item {
String name;
int price;
public static void main(String[] args) {
Item blood = new Item();
blood.name = "血瓶";
blood.price = 50;
System.out.println("装备名:"+blood.name+"\t"+blood.price+"金币");
Item straw = new Item();
straw.name = "草鞋" ;
straw.price = 300;
System.out.println("装备名:"+straw.name+"\t"+straw.price+"金币");
Item rapier = new Item();
rapier.name = "长剑";
rapier.price = 350;
System.out.println("装备名:"+rapier.name+"\t"+rapier.price+"金币");
}
}
lanren9 跳转到问题位置 答案时间:2022-11-08 ybysl 跳转到问题位置 答案时间:2022-11-02 //定义一个Hero的类
public class Hero {
String name;//英雄的姓名
float hp;//血量
float armor;//护甲
int moveSpeed;//移动速度
int money;//金钱
//这是一个无参的构造方法
public Hero() {
}
//有参的构造方法
public Hero(String name, float hp, float armor, int moveSpeed) {
this.name = name;
this.hp = hp;
this.armor = armor;
this.moveSpeed = moveSpeed;
}
public static void main(String[] args) {
//创建garen这个类
Hero garen = new Hero();
garen.name = "盖伦";
garen.hp = 616;
garen.armor = 27;
garen.moveSpeed = 350;
System.out.println("英雄的名字="+garen.name);
System.out.println("英雄的血量="+garen.hp);
System.out.println("英雄的护甲="+garen.armor);
System.out.println("英雄的移动速度="+garen.moveSpeed);
//创建一个temo这个类
Hero temo = new Hero();
temo.name = "提莫";
temo.hp = 616;
temo.armor = 27;
temo.moveSpeed = 350;
System.out.println("英雄的名字="+temo.name);
System.out.println("英雄的血量="+temo.hp);
System.out.println("英雄的护甲="+temo.armor);
System.out.println("英雄的移动速度="+temo.moveSpeed);
}
}
dyf-- 跳转到问题位置 答案时间:2022-11-02 Tt007 跳转到问题位置 答案时间:2022-10-27
public class Item {
String name;
int price;
Item(String name,int price)
{
this.name=name;
this.price=price;
}
void print()
{
System.out.println("name="+name+" "+"price="+price);
}
}
class Main
{
public static void main(String[] args)
{
Item blood=new Item("血瓶",50);
Item shoes = new Item("草鞋",300);
Item saw = new Item("长剑",350);
blood.print();
shoes.print();
saw.print();
}
}
南苛 跳转到问题位置 答案时间:2022-10-26 package practice;//前端
class Item {
String name;
int price ;
}
public class five {
public static void main(String[] args) {
Item item1=new Item();
item1.name="bloodBottle";
item1.price=50;
Item item2=new Item();
item2.name="grassShoes";
item2.price=300;
Item item3=new Item();
item3.name="sword";
item3.price=350;
}
}
bone_xxy 跳转到问题位置 答案时间:2022-10-23 he11oworld 跳转到问题位置 答案时间:2022-10-21 public class Item{
String name;
int price;
public static void main(String[] args) {
Item xp = new Item();
xp.name = "血瓶";
xp.price = 50;
Item cx = new Item();
cx.name = "草鞋";
cx.price = 300;
Item cj = new Item();
cj.name = "长剑";
cj.price = 350;
}
}
5影 跳转到问题位置 答案时间:2022-10-17 llw乌哈怪 跳转到问题位置 答案时间:2022-10-11 package hero;
public class Item {
String name;//名称
int price;//价格
public static void main (String[] args){
Item xueping = new Item();
xueping.name = "血瓶";
xueping.price = 50;
Item caoxie = new Item();
caoxie.name = "草鞋";
caoxie.price = 300;
Item changjian = new Item();
changjian.name = "长剑";
changjian.price = 350;
}
}
5217 跳转到问题位置 答案时间:2022-10-05
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2022-09-14
本题回答
2022-08-29
答
2022-07-30
1
提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 197 条以前的提问,请 点击查看
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|