From cfea1c33786995e1dea21c130a7c0c7625679ed6 Mon Sep 17 00:00:00 2001 From: pxygoafz5 <1094363854@qq.com> Date: Wed, 13 Dec 2023 16:53:57 +0800 Subject: [PATCH] ADD file via upload --- 新建 文本文档 (1).txt | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 新建 文本文档 (1).txt diff --git a/新建 文本文档 (1).txt b/新建 文本文档 (1).txt new file mode 100644 index 0000000..d6669a3 --- /dev/null +++ b/新建 文本文档 (1).txt @@ -0,0 +1,44 @@ + 张三 18 +package case1; + +public class TestPersonDemo { + public static void main(String[] args) { + /********* begin *********/ + // 声明并实例化一Person对象p + Person p1=new Person(); + // 给p中的属性赋值 + String name=p1.getName(); + name="张三"; + p1.setName(name); + int age=p1.getAge(); + age=18; + p1.setAge(age); + // 调用Person类中的talk()方法 + p1.talk(); + /********* end *********/ + } +} +// 在这里定义Person类 +class Person { + /********* begin *********/ + private String name; + private int age; + public String getName(){ + return name; + } + public void setName(String name){ + this.name=name; + } + public int getAge(){ + return age; + } + public void setAge(int age){ + this.age=age; + } + public void talk(){ + System.out.println("我是:"+name+",今年:"+age+"岁"); + } + /********* end *********/ +} + +