其他分享
首页 > 其他分享> > 类与对象的关系

类与对象的关系

作者:互联网

类与对象的关系

image

package com.oop.demo02;
//学生类
public class Student {
    //属性
    String name;
    int age;
    //方法
    public void study(){
        System.out.println(this.name+"学生在学习");
    }
}

/*
package com.oop.demo02;
//一个项目只存在一个main方法
public class Application {
    public static void main(String[] args) {
        //类:抽象的,实例化
        //类实例化后返回一个自己的对象
        //student对象就是Student类的具体实例化
        Student xiaoming = new Student();
        Student hong = new Student();

        xiaoming.name = "x小明";
        xiaoming.age = 3;

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

        hong.name = "红";
        hong.age = 3;

        System.out.println(hong.name);
        System.out.println(hong.age);
    }
}

标签:关系,xiaoming,name,对象,System,hong,Student,out
来源: https://www.cnblogs.com/jinghaha/p/15530338.html