面向对象

面向对象

         

 

 

 

 

 

 


 

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

 
package base.oop.demo01.demo02;
//一个项目应该只存在一个main方法

public class Application {
  public static void main(String[] args) {
      //类:抽象的,需要实例化
      //类实例化后会返回一个自己的对象
      //student对象就是一个Student类的具体实例!
      Student student = new Student();
      Student xiaoming= new Student();
      Student xiaohong = new Student();
      xiaoming.name="小明";
      xiaoming.age=20;
      xiaohong.name="小红";
      xiaohong.age=18;
      System.out.println(xiaoming.name);
      System.out.println(xiaoming.age);
      System.out.println(xiaohong.name);
      System.out.println(xiaohong.age);

  }
}

 

 

posted @ 2022-05-16 16:52  怎样的人生  阅读(20)  评论(0)    收藏  举报