解决方案 »
- 求助:TCP层CLOSE_WAIT,在JAVA中怎么判断这个状态?
- CentOS6下安装MyEclipse
- 关于ant junit 报classnotfoundexception的问题
- 急··~~~java用SSH框架如何控制登录的权限
- 问一hibernate难提,高手请进
- 高分请教Hibernate的问题,找不到net.sf.hibernate包
- web服务器:tomcat,数据库:sql server 用户登录时间不能满足要求,根本问题在那里呢??
- 高手帮帮忙,9点以前结贴!
- 哪里有weblogic6.1 sp4 下载!!!
- 大神看看ssh中上sql语句哪里有错 nested exception is org.hibernate.hql.ast.QuerySyntaxExceptio
- 面试面试
- commons-Validate的例子导进去总是报这个错..!求高手解决.急
你写上也好啊,只是java不写就默认为this.
private String name; public String getName() {
return this.Name;
} public void setName(String name) {
this.name = name;
}
}
自己对比下区别吧。
this代表当前对象的外部
this不能在类定义使用,只能在类定义的方法中使用
public class Parent {
private String name = "P.name";
public int age = 1; public Parent(){
super();
}
public Parent(String name){
this(); // this 作为构造函数使用
this.name = name;
}
public Parent(String name, int age){
this(); // this 作为构造函数使用
this.name = name;
this.age = age;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name; // this使用,this.name确定为本对象属性,与参数name做区分
} public void test(){
// this使用, 这里的this要不要都可以。根据个人习惯而已。
System.out.println("name="+this.name+";age="+this.age);
}
public static void main(String[] args) {
Parent p = new Child();
p.test(); //输出是什么? 答案:name=P.name;age=1
}
}class Child extends Parent {
private String name = "Child.name";
public int age = 2;
}