• 定义类Human,具有若干属性和功能;定义其子类Man、Woman; 在主类Test中分别创建子类、父类和上转型对象,并测试其特性。


    package com.hanqi.test;
    
    public class Humen {
        private String speak;
        private String read;
        private String listen;
        public String getSpeak() {
            return speak;
        }
        public void setSpeak(String speak) {
            this.speak = speak;
        }
        public String getRead() {
            return read;
        }
        public void setRead(String read) {
            this.read = read;
        }
        public String getListen() {
            return listen;
        }
        public void setListen(String listen) {
            this.listen = listen;
        }
        
        public void run()
        {
            System.out.println("我会跑");
        }
        public void jump()
        {
            System.out.println("我会跳");
        }
        
    
    }
    package com.hanqi.test;
    
    public class Men extends Humen {
        
    
    }
    package com.hanqi.test;
    
    public class Women extends Humen {
    
    }
    package com.hanqi.test;
    
    public class Testmen {
    
        public static void main(String[] args) {
    
                Humen h=new Men(); 
                
                Men m=(Men)h;
                
                m.run();
                Women w=new Women();
                
                w.jump();
    
        }
    
    }

  • 相关阅读:
    Difference between sendRedirect, include, forward
    Selenium Study Notes
    Java基础知识2
    JSP上的JavaBeans
    Java Socket 7部曲
    Javascript版本排序1
    Java基础知识1
    JavaBean的属性
    测试基础
    annotation本质
  • 原文地址:https://www.cnblogs.com/diaozhaojian/p/5897593.html
Copyright © 2020-2023  润新知