Java学习-练习-Day-02

题目来源:《疯狂Java讲义》

1
package day2;

public class Student {
    public static class StudentInfo{
        private String name;
        private int age;
        private int gender;
        private String phone;
        private String address;
        private String email;

        public String getName() {
            return name;
        }
        public int getAge() {
            return age;
        }
        public int getGender() {
            return gender;
        }
        public String getPhone() {
            return phone;
        }
        public String getAddress() {
            return address;
        }
        public String getEmail() {
            return email;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public void setGender(int gender) {
            this.gender = gender;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public StudentInfo(){
            this.name = "";
            this.age = 0;
            this.gender = 0;
            this.phone = "";
            this.address = "";
            this.email = "";
        }
        public StudentInfo(String name,int age,int gender,String phone,String address,String email){
            this.name = name;
            this.age = age;
            this.gender = gender;
            this.phone = phone;
            this.address = address;
            this.email = email;
        }
        public void action(){
            System.out.println("吃喝玩乐");
        }
    }
    public static void main (String[] args){
        StudentInfo s1 = new StudentInfo();
        System.out.println("默认构造器生成实例对象s1");
        System.out.println(s1.getName());
        System.out.println(s1.getAge());
        System.out.println(s1.getGender());
        System.out.println(s1.getPhone());
        System.out.println(s1.getAddress());
        System.out.println(s1.getEmail());
        StudentInfo s2 = new StudentInfo("Tim",22,2,"123456","address","email");
        System.out.println("带所有成员变量构造器生成实例对象s2");
        System.out.println(s2.getName());
        System.out.println(s2.getAge());
        System.out.println(s2.getGender());
        System.out.println(s2.getPhone());
        System.out.println(s2.getAddress());
        System.out.println(s2.getEmail());
        s2.action();
    }
}

你可能感兴趣的:(Java学习-练习-Day-02)