1 package bao1;
2
3 public class People
4 {
5 private String name;
6 private int age;
7 private String six;
8 private double hight;
9
10 People(String name,int age,String six,double hight)
11 {
12 this.name=name;
13 this.age=age;
14 this.six=six;
15 this.hight=hight;
16 }
17
18 public void getshuohua()
19 {
20 System.out.println("你好");
21 }
22
23 public void getjisuan()
24 {
25 System.out.println("23+45="+(23+45));
26
27 }
28
29 public String setname(String name)
30 {
31 return this.name=name;
32 }
33
34
35 public static void main(String[] args)
36 {
37 People people1=new People("张三",18,"男",1.80);
38 people1.getshuohua();
39 people1.getjisuan();
40 people1.setname("李四");
41 System.out.println(people1.name);
42 }
43 }
44 /*
45 题目按要求编写Java应用程序。
46 (1)创建一个叫做People的类:
47 属性:姓名、年龄、性别、身高
48 行为:说话、计算加法、改名
49 编写能为所有属性赋值的构造方法;
50 (2)创建主类:
51 创建一个对象:名叫“张三”,性别“男”,年龄18岁,身高1.80;
52 让该对象调用成员方法:
53 说出“你好!”
54 计算23+45的值
55 将名字改为“李四”
56 */