The Java Package

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.