面向对象
作者:互联网
面向对象
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);
}
}
标签:xiaoming,name,xiaohong,System,面向对象,Student,out 来源: https://www.cnblogs.com/zenyangderensheng/p/16277541.html