<a target="_blank" href="http://blog.51cto.com/attachment/201105/095445583.png"></a>
记住:在java里是万物皆对象!!你要深刻体会,你看到一东西要想到,它是一个对象,它具有什么特征,它能进行什么操作。理解一下,体会一下。。。。。。
<a target="_blank" href="http://blog.51cto.com/attachment/201105/095619300.png"></a>
他们都属于一个“车类” ,因为它们具有共同的属性和方法,你能理解吗?深刻体会一下:
<a target="_blank" href="http://blog.51cto.com/attachment/201105/095935162.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201105/100056502.png"></a>
实例变量就是我们刚才说的对象的共同特征:属性!记住了!
<a target="_blank" href="http://blog.51cto.com/attachment/201105/100244721.png"></a>
从面向对象开始,我们要把类的声明与使用分开了!我们都会单独声明一个类,包括属性和方法。然后会另外在一个Text类中对声明的类进行“实例化”。
上面的程序分为三段,第一段是:给Car类实例化一个对象mycar;第二段是以该对象调用类的相关属性;第三段,是调用类的方法。
<a target="_blank" href="http://blog.51cto.com/attachment/201105/101011128.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201105/101023317.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201105/101034418.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201105/101045129.png"></a>
对于方法,我这里用言语表达不好。因为必须要有实际的例子给大家展示才能理解。一会儿,给大家一些程序,我会注明每步的意思。你们下载一下就行了。
<a target="_blank" href="http://blog.51cto.com/attachment/201105/101246798.png"></a>
你应该能看懂。就是类声明的变量,方法可以用。但是方法声明的变量只能在方法体力运用。
本文转自韩立伟 51CTO博客,原文链接:http://blog.51cto.com/hanchaohan/560397,如需转载请自行联系原作者