zoukankan      html  css  js  c++  java
  • Java学习的第五十三天

    1.例9.5引用静态数据成员

    public class Cjava {
    public static void main(String[]args) {
    Box b[] = {new Box(12,15),new Box(18,20)};
    System.out.println("h of b[0]="+b[0].h+"The volume of b[0]="+b[0].volume());
    System.out.println("h of b[1]="+b[1].h+"The volume of b[1]="+b[1].volume());
        }
    }
    class Box{
        static int h=5 ;int w,l;
        Box(int y,int z){
            w=y;l=z;
        }
        int volume(){
            return (h*w*l);
        }
    }

    例9.6引用静态方法

    public class Cjava {
    public static void main(String[]args) {
    Student s[]= {new Student(1001,18,70),new Student(1002,19,78),new Student(1005,20,98)};
    for(int i=0;i<s.length;i++) {
        s[i].total();
    }
    System.out.println("平均分为:"+Student.average());
        }
    }
    class Student{
        int num;int age;float score;static float sum;static int count;
        Student(int n,int a,float s){
            num=n;age=a;score=s;
        }
        void total(){
            sum=sum+score;
            count++;
        }
        static float average() {
            return (sum/count);
        }
    }

     2.没问题

    3.明天继续写例题

  • 相关阅读:
    chapter4.6生成器
    chapter4.4、递归
    chapter4.3、函数执行流程
    chapter4.2、函数返回值
    直接插入排序
    打印三角型的练习
    杂记
    linux top命令
    makefile 中的 := , += ,?=
    makefile中的shell语法 || Makefile中的@
  • 原文地址:https://www.cnblogs.com/feng747/p/13576980.html
Copyright © 2011-2022 走看看