------------------android培训 java培训----------------期待与您交流‘
关于构造代码块:
每个构造函数执行之前都会执行到的代码块
{
System.out.println(“构造代码块”);
}
this:代表本类的对象,this代表它所在函数所属对象的引用。也就是说是哪个对象在调用this所在函数,就是指哪个对象。
this关键字在构造函数中的使用:
this语句 用于构造函数之间调用,且只能放在第一行
class Person
{
Stringname;
intage;
Person(String name)
{
this.name = name;
}
Person(String name,int age)
{
this(name);
this.age = age;
}
publicstatic void main(String[] args)
{
}
}