1、类,对一类事物的描述是抽象的,
对象,是该类事物中的一个个实实在在的个体;
2、对象的抽象化就是类,
类的具体化就是抽象;
3,类,使用class关键字定义
对象,在堆内存中通过new关键字来创建实体
4,注意地址的不同,如下例:
- class Cars
- {
- String color = "red";
- int nums =4;
-
- public void run()
- {
- System.out.println("color is:"+this.color+";num is "+this.nums);
- }
- }
- public class myCars
- {
- public static void main(String[] args)
- {
- Cars c1 = new Cars();
- c1.run();
- c1.color = "blue";
- c1.run();
-
- Cars c2 = new Cars();//c2 address is different from c1
- c2.run();
-
- Cars c3 = c1;//c3 and c1 are both same place
- c3.run();
- }
- }
复制代码 |
|