您现在的位置是:主页 > news > 电商平台介绍网站模板/今日头条搜索优化

电商平台介绍网站模板/今日头条搜索优化

admin2025/4/26 5:44:57news

简介电商平台介绍网站模板,今日头条搜索优化,.net网站开发简介,国内商务网络公司排名this表示的是当前对象,即this所在的方法被那个对象所调用_这个this指的就是这个对象,可看成this持有当前对象的地址值 ex:Student s new Student(); this有点类似 s对象, 持有对象地址 this的作用: ①this表示当前对象&#xf…

电商平台介绍网站模板,今日头条搜索优化,.net网站开发简介,国内商务网络公司排名this表示的是当前对象,即this所在的方法被那个对象所调用_这个this指的就是这个对象,可看成this持有当前对象的地址值 ex:Student s new Student(); this有点类似 s对象, 持有对象地址 this的作用: ①this表示当前对象&#xf…

this表示的是当前对象,即this所在的方法被那个对象所调用_这个this指的就是这个对象,可看成this持有当前对象的地址值

ex:Student s = new Student(); this有点类似 s对象, 持有对象地址

this的作用:

①this表示当前对象:就是说,谁调用了当前方法(this所在的方法),谁就是this   

②在构造方法中调用本类的构造方法

       this();    表示调用本类中无参数的构造方法

       this(...);   表示调用本类中具有指定参数的构造方法

      (注意:this();和this(...);只能够是在构造方法中,并且是第一句,避免递归调用,不能在普通方法中使用)

③作为方法参数传递

④作为返回值返回 

       this既然表示的当前的一个对象,对象就是一个数据,一个数据就可以作为值被返回

ex:

class Test{public static void main(String[] args) {Student s = new Student();s.test1();System.out.println("s   :"+s);  //Student@15db9742System.out.println(s.getName());Student s2 = new Student();Student s3 = s2.test3();System.out.println("s2  :"+s2);//Student@6d06d69cSystem.out.println("s3  :"+s3);//Student@6d06d69c}
}
class Student{private String name;public Student(){this("张三");//调用本类的有一个String类型参数的构造方法//this();//形成了方法的递归调用了  即反复调用Student(){}会报错!!}public Student(String name){	this.name = name;}public void setName(String name){//System.out.println(this);//Student@15db9742this.name = name;}public String getName(){//this();//想要在普通方法中使用this()调用构造方法。 结果:报错return this.name;}public void test1(){//把this作为方法参数: 也就是说把调用当前test1方法的对象作为实参传给test2方法的形参test2(this);//this表示当前对象。当前场景下,this指的就是sSystem.out.println("test1方法中:"+this);   //Student@15db9742}public void test2(Student student){   //这里的student接收的是test1中的this  即s对象System.out.println("test2方法中:"+student);  //Student@15db9742}//把this作为返回值public Student test3(){System.out.println("test3方法中:"+this);//这里的this指的是s2对象  Student@6d06d69creturn this;//也就是说:把调用当前test3方法的对象作为返回值返回给方法}
}

this的堆栈分析图: