A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© a80C51 中级黑马   /  2015-8-30 11:29  /  205 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1、类,对一类事物的描述是抽象的,

     对象,是该类事物中的一个个实实在在的个体;

2、对象的抽象化就是类,

     类的具体化就是抽象;

3,类,使用class关键字定义

     对象,在堆内存中通过new关键字来创建实体

4,注意地址的不同,如下例:

  1. class Cars
  2. {
  3.         String color = "red";
  4.         int nums =4;
  5.        
  6.         public void run()
  7.         {
  8.                 System.out.println("color is:"+this.color+";num is "+this.nums);
  9.         }
  10. }

  11. public class myCars
  12. {
  13.         public static void main(String[] args)
  14.         {
  15.                 Cars c1 = new Cars();
  16.                 c1.run();
  17.                 c1.color = "blue";
  18.                 c1.run();
  19.                
  20.                 Cars c2 = new Cars();//c2 address is different from c1
  21.                 c2.run();
  22.                
  23.                 Cars c3 = c1;//c3 and c1 are both same place
  24.                 c3.run();
  25.         }
  26. }
复制代码

1 个回复

正序浏览
谢谢楼主分享总结
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马