package com.encapsulation; public class Student { private double score; public void setSore(double score){ if (score>=0 && score<=100){ this.score=score; }else { System.out.println("数据非法"); } } public double getScore(){ return score; } public void printPass(){ System.out.println(score>=60?"成绩合格":"成绩不合格"); } }
package com.encapsulation; public class Test { public static void main(String[] args) { Student s1=new Student(); s1.setSore(99); System.out.println(s1.getScore()); } }
标签:s1,setSore,score,void,Student,使用,public From: https://www.cnblogs.com/Karl-hut/p/17437988.html