12.10作業4
阿新 • • 發佈:2018-12-16
/*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()方法。*/
public class Proson {
String name;
int age;
double height;
void sayHello(){
System. out.println(name+","+age+"歲,"+"身高"+height);
}
}
``
```java
public class PersonCreate {
public static void main(String[] args) {
Proson p1 = new Proson();
p1.name = "zhangsan";
p1.age = 33;
p1.height = 1.73;
p1.sayHello();
Proson p2 = new Proson();
p2.name = "lisi";
p2.age = 44;
p2.height = 1.74;
p2.sayHello();
}
}