封装
作者:互联网
package com.liu.oop;
//以类的方式组织代码,以对象的组织(封装)数据。
public class Student {
//属性:字段
String name;
int age;
//方法
public void study(){
System.out.println(this.name+"在学习");
}
}
/*
public class Application {
public static void main(String[] args) {
//类:抽象的
//类实例化后会返回一个自己的对象
Student xm = new Student();
Student xh = new Student();
xm.name = "小明";
xm.age = 10;
System.out.println(xm.name);
System.out.println(xm.age);
xm.study();
xh.name = "小红";
xh.age = 10;
System.out.println(xh.name);
System.out.println(xh.age);
xh.study();
}
}
*/
标签:xh,封装,name,xm,System,Student,out 来源: https://www.cnblogs.com/sm12580/p/15293359.html