zoukankan      html  css  js  c++  java
  • java,作业水果,运用类的静态和重载

    package wanzai;
    
    public class Fruit {
        private static  Fruit color=null;
        private Fruit()
        {
            
        }
        public static Fruit getcolor(){
            if(color==null){
                color=new Fruit();
                
            }
            return color;
        }
        public void setcolor()
        {
            System.out.println();
        }
        public static void main(String[] args) {
            System.out.println("苹果颜色是红色");
            Fruit color1=Fruit.getcolor();
            color1.setcolor();
            System.out.println("香蕉颜色是黄色");
            Fruit color2=Fruit.getcolor();
            color2.setcolor();
        
            
    
    }
    }

    package wanzai;
    
    public class Fruit1 {
        public double price(double price){
            return price;
        }
        public int price(int weigth){
            return weigth;
        }
                
        public static void main(String[] args)
        {
            Fruit1 apple=new Fruit1();
            System.out.println("苹果的价格是"+apple.price(5.5));
            System.out.println("苹果的重量是"+apple.price(10));
            Fruit1 banana=new Fruit1();
            System.out.println("香蕉的价格是"+banana.price(4.2));
            System.out.println("香蕉的重量是"+banana.price(5));
        }
        
        }

  • 相关阅读:
    Leetcode#145 Binary Tree Postorder Traversal
    Leetcode#146 LRU Cache
    单引号和双引号的区别
    $* $@ $#
    pthread_detach
    pthread_join
    intent 启动activity、service的方法
    multicast based on udp
    ARM指令系统
    ARM寄存器
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/5252658.html
Copyright © 2011-2022 走看看