面向对象
封装
package com.oop.demo04;public class Application {
public static void main(String[] args) {
Student s1 = new Student();s1.setName("Yoona");System.out.println(s1.getName());s1.setAge(999);System.out.println(s1.getAge());}
}
package com.oop.demo04;
public class Student {
private String name; private int id;private char sex; private int age;public String getName() {
return this.name;}public void setName(String name) {
this.name = name;}public int getAge() {
return age;}public void setAge(int age) {
if (age > 120 || age < 0)this.age = 3;else {
this.age = age;}}
}