• 在包a中编写一个类Father,具有属性:年龄(私有)、姓名(公有); 具有功能:工作(公有)、开车(公有)。 在包a中编写一个子类Son,具有属性:年龄(受保护的)、姓名; 具有功能:玩(私有)、学习(公有)。 最后在包b中编写主类Test,在主类的main方法中测试类Father与类Son。


    package a;
    
    public class Father {
         public String name;
         private int age;
         public Father(String name)
         {
             this.name=name;
         }
        public int getAge() 
        {
            return age;
        }
        public void setAge(int age) 
        {
            this.age = age;
        }
        public Father(int age)
        {
            super();
            this.age = age;
        }
    
         public void gongzuo()
         {
             System.out.println("父亲的工作");
         }
         public void kaiche()
         {
             System.out.println("父亲开车");
         }
      }  
     
    package a;
    
    public class Son {
        protected int age;
        String name;
        
        public Son(int age)
        {
            super();
            this.age = age;
        }
        public Son(String name)
        {
            this.name=name;
        }
        private void wan()
        {
            System.out.println("儿子玩");
        }
        public void xvexi()
        {
            System.out.println("儿子的学习");
        }
        
    package b;
    import a.Father;
    import a.Son;
    public class Test {
    
        public static void main(String[] args) {
            Father fuqin=new Father("");
            Son erzi=new Son("");
            fuqin.gongzuo();
            fuqin.kaiche();
           // erzi.wan();
            erzi.xvexi();
        }
    
    }

  • 相关阅读:
    bbb SOCKET CAN
    在BBB上使用CCS5开发环境
    BBB的PRU模块
    垃圾邮件分类
    yzoj 2377 颂芬梭哈 题解
    yzoj 2372 小B的数字 题解
    yzoj P2371 爬山 题解
    hdu 1007 Quoit Design 题解
    手写堆
    yzoj P1126 塔 题解
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5505741.html
Copyright © 2020-2023  润新知