A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© zhouzhiming88 中级黑马   /  2015-5-21 23:48  /  449 人查看  /  7 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*
        案例:定义学生类。
*/
class Student     
{        String name;
        int age;
        static String country;
        //无参构造
        public Student(){
                System.out.println("无参构造方法");
        }

        //有参构造
    public Student(String name,int age){
                this.name=name;
                this.age=age;
                this.country=country;
         }
    public Student(String name,int age,String country){
                this.name=name;
                this.age=age;
                this.country=country;
        }
        public void show(){
                System.out.println(name+"****"+age+"****"+country);
        }
        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;
        }
}       
       
class StaticTest
{
        public static void main(String[] args)
        {
               
                //创建对象
                Student s1=new Student("林青霞",26);
                s1.show();
                Student s2=new Student("郝永亮",27,"中国");
                s1.show();
        }
}
输出的结果是过少?

7 个回复

倒序浏览
林青霞****26****null
林青霞****26****中国
回复 使用道具 举报
林青霞****26****null 林青霞****26****中国
回复 使用道具 举报
林青霞**26****null
回复 使用道具 举报
林青霞***26****null
林青霞***26***中国
是吗?
回复 使用道具 举报
static是静态修饰符,被static修饰的成员在本类是共享的。
回复 使用道具 举报
914360849 发表于 2015-5-22 21:44
林青霞***26****null
林青霞***26***中国
是吗?

是的:handshake
回复 使用道具 举报
好的不错。学习了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马