流觞区直

导航

8.1 面向对象三大特征之封装性

 面向对象三大特征:封装、继承、多态

 

封装性在Java当中的体现:

1.方法就是一种封装

2.关键字private也是一种封装

 

封装就是将一些细节信息隐藏起来,对外界不可见。

 

public class Demo01Method {
    public static void main(String[] args) {
        int[] array = {5,10,25,20,100};

        int max = getMax(array);
        System.out.println("最大值:"+ max);
    }
    public static int getMax(int[] array){
        int max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (array[i]>max){
                max =array[i];
            }
        }
        return max;
    }

}

  

posted on 2019-06-30 15:01  流觞区直  阅读(198)  评论(0编辑  收藏  举报