成员变量与局部变量的区别:
public class ThisTest {
public static void main(String[] args) {
Student stu=new Student();
stu.show();
}
}
class Student{
//成员变量
int num=10;
public void show(){
//局部变量
int num=20;
System.out.println(num);
System.out.println(this.num);
}
第一行输出:20
第二行输出:10
如果想输出成员变量的值需要使用this关键字;
this 代表当前类对象的引用(地址),可以处理局部变量和成员变量重名的问题;