this关键字
来源:互联网 发布:灵魂相认知乎 编辑:程序博客网 时间:2024/05/01 00:50
package test;
//The declared package "" does not match the expected package "test"
public class Student {
String name;
String age;
String hight;
String weight;
public Student() { // 构造方法没有返回值?是的,构造方法没有返回值
this("hgl"); // 调用类的构造方法,只有在无参数构造方法中第一句使用this调用有参数的构造方法,传统的方法如何调用构造方法?
}
public Student(String name) {
System.out.println("带形参的构造方法");
}
public String getName() {
return this.name; // 调用成员变量,this 代表调用setName方法的对象的引用,即对象名称
}
public void setName(String name) {
this.name = name; // 调用成员变量,this
// 代表调用setName方法的对象的引用,即对象名称,以便区分成员变量和形参(局部变量)
}
public Student testReturn() {
System.out.println("这个方法返回Student类型的对象");
return this; // 返回Student类型的对象引用
}
public static void main(String[] args) {
Student stu = new Student();
stu.setName("hgl");
String name1 = stu.getName();
System.out.println(name1);
}
}
//The declared package "" does not match the expected package "test"
public class Student {
String name;
String age;
String hight;
String weight;
public Student() { // 构造方法没有返回值?是的,构造方法没有返回值
this("hgl"); // 调用类的构造方法,只有在无参数构造方法中第一句使用this调用有参数的构造方法,传统的方法如何调用构造方法?
}
public Student(String name) {
System.out.println("带形参的构造方法");
}
public String getName() {
return this.name; // 调用成员变量,this 代表调用setName方法的对象的引用,即对象名称
}
public void setName(String name) {
this.name = name; // 调用成员变量,this
// 代表调用setName方法的对象的引用,即对象名称,以便区分成员变量和形参(局部变量)
}
public Student testReturn() {
System.out.println("这个方法返回Student类型的对象");
return this; // 返回Student类型的对象引用
}
public static void main(String[] args) {
Student stu = new Student();
stu.setName("hgl");
String name1 = stu.getName();
System.out.println(name1);
}
}
0 0
- 关键字this
- this关键字
- this关键字
- this 关键字
- this 关键字
- this关键字
- this关键字
- this 关键字
- this 关键字
- this 关键字
- this关键字
- 关键字this
- 关键字this
- this 关键字
- this 关键字
- this关键字
- this关键字
- This关键字
- Spring注解Annotation
- Apache中如何设置网站默认首页?
- HDU 2896 - 病毒侵袭 (AC自动机)
- 朝花夕拾:CSDNBlog使用方法(非官方,持续更新)(已更新二次)
- Eclipse上的Web项目调试
- this关键字
- 【ORACLE】sql*loader的实验一
- Class 和 xml 之间的相互转化
- eclipse安装内存分析工具
- ubuntu: eclipse和gdb调试jni代码;gcj调试jni代码
- 成为高手必须掌握哪几种语言
- mysql 字符集设置
- android中隐藏ListView滚动条
- sqrt()函数详解