java中super()和this()、super和this的区别 java中super()和this()、super和this的区别

1.super()和this()区别:   

                            super():调用父类无形参的构造方法;

                            super(形参):调用父类中某个带形参的构造方法;

                            this(形参):调用本类中另一种形式的构造方法;

          注意:放在方法的首行;

2.super和this的区别:

          super.父类的成员变量;

          super.父类的方法;

          super:当子类中的成员变量、方法和父类的相同时,实现调用父类的成员变量和方法;

          this:代表当前的对象;

                                   使用的地方:若函数的形参和成员变量同名时,需要用this.成员变量名

扫描二维码关注公众号,回复: 6388788 查看本文章

原文出处:

sunruntheway,  java中super()和this()、super和this的区别https://www.cnblogs.com/sunruntheway/p/sunruntheway.html

 
 

猜你喜欢

转载自www.cnblogs.com/ryelqy/p/10996185.html