沈阳的网站建设,全国建筑资质查询网站,四川德行天下建设工程有限公司网站,怎么在网站上添加广告代码1.属性私有#xff0c;get/set
2.封装#xff1a;数据的隐藏
3.该漏漏#xff0c;该藏藏#xff1a;程序要求高内聚、低耦合#xff0c;高内聚指类的内部数据操作细节自己完成#xff0c;低耦合是提供少量方法供外部使用
package com.wuming.oop.demo04;
//类 private…1.属性私有get/set
2.封装数据的隐藏
3.该漏漏该藏藏程序要求高内聚、低耦合高内聚指类的内部数据操作细节自己完成低耦合是提供少量方法供外部使用
package com.wuming.oop.demo04;
//类 private:私有
public class Student {//属性私有private String name;//名字private int id;//学号private char sex;//性别private int age;public int getAge() {return age;}public void setAge(int age) {if (age120 || age0){//不合法this.age3;}else{this.age age;}}//altinsertpublic int getId() {return id;}public void setId(int id) {this.id id;}//提供一些可以操作这个属性的方法//提供一些public的get、set方法//get获取这个数据public String getName(){return this.name;}//set给这个数据设置值public void setName(String name){this.namename;}
}
同一个包下再创一个类
package com.wuming.oop.demo04;public class Application {public static void main(String[] args) {Student s1 new Student();s1.setName(秦僵);System.out.println(s1.getName());s1.setAge(-1);//不合法的System.out.println(s1.getAge());}
}秦僵 3