//4、定义两个类,描述如下: [必做题]//4.1定义一个人类Person://4.1.1定义一个方法sayHello(),可以向对方发出问候语“hello,my name is XXX”//4.1.2有三个属性:名字、身高、体重//4.2定义一个PersonCreate类://4.2.1创建两个对象,分别是zhangsan,33岁,1.73;lishi,44,1.74//4.2.2分别调用对象的sayHello()方法。publicclassPerson{
String name;int age;double high;double weight;voidsayHello(){
System.out.println("hello,my name is "+name+"我今年"+age+"岁,身高"+high+"体重"+weight);}}publicclassPersonCreate{publicstaticvoidmain(String[] args){
Person zhangsan=newPerson();
zhangsan.name="张三";
zhangsan.age=33;
zhangsan.weight=33;
zhangsan.high=1.73;
Person lisi=newPerson();
lisi.name="李四";
lisi.age=44;
lisi.weight=1.74;
lisi.high=44;
zhangsan.sayHello();
lisi.sayHello();}}
//5、定义两个类,描述如下: [必做题]//5.1定义一个人类Person://5.1.1定义一个方法sayHello(),可以向对方发出问候语“hello,my name is XXX”//5.1.2有三个属性:名字、身高、体重//5.1.3通过构造方法,分别给三个属性赋值//5.2定义一个Constructor类://5.2.1创建两个对象,分别是zhangsan,33岁,1.73;lishi,44,1.74//5.2.2分别调用对象的sayHello()方法。publicclassPerson{
String name;int age;double high;int weight;voidsayHello(){
System.out.println("hello,my name is "+name+"年龄"+age+"身高"+high+"体重"+weight);}Person(String name,int age,double high,int weight){this.name=name;this.age=age;this.high=high;this.weight=weight;}}publicclassConstructor{publicstaticvoidmain(String[] args){
Person zhangsan=newPerson("张三",33,1.73,33);
Person lisi=newPerson("李四",44,1.74,44);
zhangsan.sayHello();
lisi.sayHello();}}