Package Performance:
1, the method is a most basic package body.
2, the class is actually a package body.
Advantage:
1 improved reusability of the code
2 hides the implementation details and provides access to external methods
3 Improved security
About the keyword private private (permission modifier)
Format: Added before data types and methods, and the properties and methods are private.
1 Packagecom.oracle.demo01;2 3 Public classSchool {4 5 Public Static voidMain (string[] args) {6 //Creating Objects7Teacher T =NewTeacher ();8 //Calling Methods9T.setname ("LZ");TenT.setage (13); One T.shuchu (); A //Take value -System.out.println (T.getage () + "..." +t.getname ()); - } the -}
1 Packagecom.oracle.demo01;2 //Create a class3 Public classTeacher {4 //Privatization Properties5 PrivateString name;6 Private intAge ;7 //use methods to assign values8 Public voidSetage (inta) {9Age =A;Ten } One Public voidSetName (String N) { AName =N; - } - //use method to take value the Public intGetage () { - returnAge ; - } - PublicString GetName () { + returnname; - } + //Output Control Desk A Public voidShuchu () { at -System.out.println ("The teacher's name is" +name+ ", The Age is" +Age ); - } - -}
The Java Package