Person thisPerson = null;
thisPerson = new Person();
两句加起来就等于:
Person thisPerson=new Person();
一般后者是用于定义一个类的实例并马上初始化。然后就可以使用了。
前者一般是你已经有了这个类的实例,但是想要换个名字使用,比如已经有个一个
Person类型的变量:thatPerson
这时候你就可以
Person thisPerson = null;
...//code
thisPerson = thatPerson;
...//code
thisPerson = new Person();
两句加起来就等于:
Person thisPerson=new Person();
一般后者是用于定义一个类的实例并马上初始化。然后就可以使用了。
前者一般是你已经有了这个类的实例,但是想要换个名字使用,比如已经有个一个
Person类型的变量:thatPerson
这时候你就可以
Person thisPerson = null;
...//code
thisPerson = thatPerson;
...//code
解决方案 »
- java内置的多线程技术和调用操作系统的多线程机制有什么不同?
- 一个JTree问题
- 谁能告诉我 Struts 技术的编译环境的下载地址
- 我的计算机现在死机,显卡不是很热,cpu不热 是什么原因会司机呢?是病毒吗
- 我的配置为什么老出现Exception in thread "main" java.lang.NoClassDefFoundError: test
- 抽象类我该怎么实力化它呢?例如要申明一个Image对象该怎么做?
- 求助:关于静态变量的实例化
- 如何用Jconnect连接局域网中的另外一台电脑的Sybase 数据库啊。在线等!
- 高手请进,中文乱码问题,这是我同一个问题的第五个帖子了,大伙帮忙,心情好郁闷.期待高手.
- 怎么判断一个jdk是否是国际版?
- 如何去掉JFRAME里的最小化,最大化,关闭按钮?(不是散分,只给答题的人)
- 关于 java proxy 。游戏开发,应用……
eg
Class a{
//……
Person thisPerson = null; public void init(){
thisPerson = new Person();
//……
} public void usePerson(){
thisPerson.move();
//……
}
//……
}