zoukankan      html  css  js  c++  java
  • 继承案例

    package huawei;
    
    public class Smart_phone {
        private String name;
        private int price;
        private String cofig;
    
        public void setName(String name) {
            this.name = name;
        }
    
        public void setPrice(int price) {
            if (price > 2000) {
                this.price = price;
            }
        }
    
        public void setCofig(String cofig) {
            this.cofig = cofig;
        }
    
        public String getName() {
            return name;
        }
    
        public int getPrice() {
            return price;
        }
    
        public String getCofig() {
            return cofig;
        }
    
        public void call(){
            System.out.println("打电话");
        }
        public void sendMessage(){
            System.out.println("发短信");
        }
        public void playGame(){
            System.out.println("玩游戏");
        }
        public void watchMovies(){
            System.out.println("看电影");
        }
    }

    1.华为手机类

    2.荣耀30

    package huawei;
    
    public class Honor30 extends Smart_phone {
        String color;
        public Honor30() {
           System.out.println(" Hello Honor30");
        }
    
    }

    3.华为mate30

    package huawei;
    
    public class Huawei_mate30 extends Smart_phone{
        String color;
        public Huawei_mate30() {
            System.out.println();
        }
    }

    4.华为p40_pro

    package huawei;
    
    public class Huawei_p40_pro extends Smart_phone{
        String color;
        public Huawei_p40_pro() {
            System.out.println("hello p40_pro");
        }
    }

    5.Extends_test

    package huawei;
    
    public class Extends_test {
        public static void main(String[] args){
            Honor30 hr=new Honor30();
            hr.setName("honor30");
            hr.setCofig("kirin990");
            hr.setPrice(3999);
            hr.color="silver";
            hr.call();
            hr.sendMessage();
            hr.playGame();
            hr.watchMovies();
            System.out.println(hr.getCofig()+"	"+hr.getName()+"	"+hr.getPrice()+"	"+hr.color+"	");
        }
    }

  • 相关阅读:
    2013年个人总结
    ASP.NET Core SignalR (一):SignalR 概述
    ASP.NET Core 中的配置 【上】
    .NET Core 服务器
    .NET Web 宿主(Web Host)【下】
    .NET Web 宿主(Web Host)【上】
    .NET 通用主机(Generic Host)
    ASP.NET Core中间件
    ASP.NET Core中的依赖注入【下】
    ASP.NET Core中的依赖注入【上】
  • 原文地址:https://www.cnblogs.com/resort-033/p/12979254.html
Copyright © 2011-2022 走看看