You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
408 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

public class Jb22_EncampsObj
{
//面向对象的封装
public static void main(String[] args)
{
Person xiaoMing = new Person();
xiaoMing.getAge(21);
xiaoMing.speak();
}
}
class Person
{
private int age;
public void getAge(int num)
{
if(num>=0 && num<=150)
{
age = num;
}
else
System.out.println("错误输出年龄范围在0~150");
}
void speak()
{
System.out.println("年龄是"+age);
}
}