package com.fengzhuang;
//学生类
 class Student {
private int count ;
public void setCount (int myCount) {
if (myCount<0 && myCount>10)
System.out.println(" 获取错误");
else
count=myCount;
}
public int getCount() { 
if(count<=0) {
System.out.println(" 获取错误");
return 0;
}else{
return count;
}
}
}
public class TestStudent {
public static void main(String args[]){
Student s=new Student () ;
s.setCount(11) ;
s.setCount(5);
int count=s.getCount () ;
System.out.println("Count 的值是:"+count);
s.setCount (0) ;
count=s.getCount () ;
System.out.println("Count 的值是:"+count);
}

}

课堂作业之封装

相关文章:

  • 2021-12-11
  • 2021-10-15
  • 2021-06-01
  • 2021-09-19
  • 2021-06-13
  • 2021-08-31
猜你喜欢
  • 2021-05-28
相关资源
相似解决方案