Three features of object oriented encapsulation []

Encapsulation in Java reflected among:

1. A method of packaging is; [shown in the following code sample, obtaining the maximum number is a way to package getMax]

2. The private key is also a package.

 

Packaging is to hide some of the details, not visible to the outside world.

Demo02Method class public 
{ 
    public static void main (String [] args) 
    { 
        int [] = {5,15,25,20,100 Array}; 
        int max = getMax (Array); 
        System.out.println ( "maximum value" + max ); 
    } 
// give me an array, a maximum value I for you 
    public static int getMax (int [] array) 
    { 
        int max = array [0]; 
        for (int I = 0; I <be array.length; I ++) 
        { 
            IF (Array [I]> max) 
            { 
                max = Array [I]; 
            } 
        } 
        return max; 

    } 
}

  

Guess you like

Origin www.cnblogs.com/sdrbg/p/11221413.html