- class Demo_Student2 {
- public static void main(String[] args){
- Student s = new Student();
- s.setName("李小龙");
- s.setAge(99);
-
- s.show();
- System.out.println("==========");
-
- Student s1 = new Student("丽达" ,98);
- s1.show();
- }
- }
- class Student {
- private String name ;
- private int age ;
- public Student(){}
- public Student(String name,int age){
- this.name = name ;
- this.age = age ;
- }
- public void setName(String name){
- this.name = name ;
- }
- public String getName(){
- return name ;
- }
- public void setAge(int age){
- this.age = age;
- }
- public int getAge(){
- return age ;
- }
- public void show(){
- System.out.println("我的字是"+name+"..."+"年龄是"+age);
- }
- }
复制代码 |
|