zoukankan      html  css  js  c++  java
  • java 继承练习题2

    创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople

    AmericanPeople类重写父类的三个方法)。

    package com.hanqi;
    
    public class People {
        private double height;
        private double weight;
        public double getHeight() {
            return height;
        }
        public void setHeight(double height) {
            this.height = height;
        }
        public double getWeight() {
            return weight;
        }
        public void setWeight(double weight) {
            this.weight = weight;
        }
        //打招呼
        public void speakHello()
        {
            System.out.println("Hello!");
        }
    
    }
    package com.hanqi;
    //extends 继承
    //Object 是所有类的父类】
    public class ChinaPeople extends People {
    
        public void gongfu()
        {
            System.out.println("站如松");
        }
        public void speakHello()
        {
            System.out.println("你好");
        }
    
    }
    package com.hanqi;
    
    public class AmericanPeople extends People {
        //输出拳击的信息
        public void americanBoxing()
        {
            System.out.println("直拳,勾拳");
            }
    
    }
    package com.hanqi;
    
    public class Testpeople {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
    
            People p=new People();
            p.speakHello();
            
            ChinaPeople cp=new ChinaPeople();
            cp.setWeight(100);
            
            cp.setHeight(100);
            System.out.println(cp.getHeight());
            cp.speakHello();
            cp.gongfu();
            AmericanPeople  a=new AmericanPeople();
            a.americanBoxing();
            
        }
    
    }

  • 相关阅读:
    bootstrap的引用和注意事项
    css样式表的知识点总结
    数据去重宏脚本
    redis总结
    list对象中根据两个参数过滤数据
    dt常用类
    C#删除字符串最后一个字符的几种方法
    C#的split分割的举例
    数据库优化的几个注意点
    两种转换城市的方式
  • 原文地址:https://www.cnblogs.com/jskbk/p/5516992.html
Copyright © 2011-2022 走看看