面向对象-小结一

public class Application {
public static void main(String[] args) {

    Pet dog = new Pet();
    dog.name = "旺财";
    dog.age = 3;
    dog.shout();

    System.out.println(dog.name);
    System.out.println(dog.age);

    Pet cat = new Pet();

     /*
     1、类是一个模板,是抽象的。对象是具体的实例。
     2、方法
     定义:调用!
     3、对象的引用
     基本类型(8种)
     引用类型:对象是通过引用来操作的:栈---->堆的地址
     4、属性:字段Filed  成员变量
     默认初始化:
     数字:0   0.0
     char: u0000
     boolean: false
     引用: null

     修饰符: 属性类型   属性名 = 属性值
     5、对象的创建和使用
       必须使用new关键字创造对象,构造器 Person sanwin = new Person();
       对象的属性   sanwin.name
       对象的方法   sanwin.sleep()

       6、类
       静态的属性: 属性
       动态的行为: 方法

       封装、继承、多态

     */

}

}

public class Pet {
public String name;
public int age;
//无参构造
//

public void shout(){
    System.out.println("叫了一声");
}

}

posted @ 2022-04-02 21:29  时装男人  阅读(23)  评论(0)    收藏  举报