类与对象的几点注意事项:
this关键字:
1.this关键字是什么?
this就是一个变量,可以用在方法中,用来拿到当前对象;哪个对象调用方法,this就指向哪个对象,也就是拿到哪个对象。
2.this关键字在实际开发中常用来干什么?
用来解决对象的成员变量与方法内部变量名称一样时导致访问冲突的问题。
构造器:
无参构造器:
public Student() {
}
有参构造器:
public Student(String name, double chinese) {
this.name = name;
this.chinese = chinese;
}
public Student(String name, double chinese, double math) {
this.name = name;
this.chinese = chinese;
this.math = math;
}
封装:
private隐藏对象属性,提供getter、setter方法供外部使用。
实体JavaBean:
即开发过程中的实体类。