package day18; public class Test01 { public static void main(String[] args) { Student01 s = new Student01( "贾铭", 18); System.out.println(s.getName()); System.out.println(s.getAge()); s.setName("张三"); s.setAge(15); System.out.println(s.getName()); System.out.println(s.getAge()); } } class Student01 { //3 usages private String name; //3 usages private int age; //1 usage public Student01(String name,int age){ // this 是创建的对象 s,this = s; this.name = name; this.age = age; } public void setName (String name) { //谁调用这个方法谁就是this this = s this.name = name; } public String getName(){ return name; } public void setAge(int age) { //谁调用我谁就是this this.age = age; } public int getAge() { return age; } }
2022.9.28 创建对象调用
最新推荐文章于 2024-09-05 11:00:53 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)