黑马程序员技术交流社区

标题: 面向对象6 [打印本页]

作者: 小b,试试就试试    时间: 2016-7-29 06:49
标题: 面向对象6
                狗类Dog
                        属性:姓名name,年龄age
                        行为:吃饭eat,看家lookHome

class Dog {
        public static void main(String[] args) {
                Dogl a =new Dogl();
                a.setName("狗");
                a.setAge(4);
                System.out.println(a.getName()+"  "+a.getAge());
                a.eat();
                a.lookHome();
               
        }
}

class Dogl{
        private String  name;
        private int  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 eat(){
        System.out.println("吃饭");
        }
        public void lookHome(){
        System.out.println("看家");
        }
}

作者: 敲代码小蚂蚁    时间: 2016-7-29 07:04
这个是什么 鬼?




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2