is- was-like- a -a-a relationship;
Public classanimal{ Public voidmethod01 ();}//the relationship between classes and classesclassDog extends animal{//Dog is a Animal }/////////////////////////////////////////// Public Interfacei{ Public voidmethod1 ();}//is-like-a relationship between classes and interfaces: implementationclassA Implements i{//A is like a I Public voidmethod1 () {//Implement }}
/////////////////////////////////////////////////
/*the association between classes and classes*/ Public classb{//B has a C Privatec c;}classc{}
package is actually a directory, especially when the project is large, Java files in particular, we should sub-directory management, in Java called subcontracting Management, package names are usually lowercase. 1, the package is best to use lowercase letter 2, package naming should have rules, cannot repeat //packagesmust be placed on the first line of all statements, except comments Import:1. Import statements can introduce other classes. 2 . The import statement can only appear under the package statement, the class-defined statement above the JDK Common development package: Java.lang, the package Java language Standard package, which uses the contents of this bundle without importing the java.sql, provides the JDBC interface class Java . util, which provides a common tool class java.io, provides a variety of input and output streams
/*the charter system of the Software: 1. In order to resolve the naming conflict problem of a class, add a namespace (package mechanism) before the class name 2. Use the package statement in Java to define packages. (Single bag, re-bag) 3. The package statement can only appear in the first line of the. Java source file, 4. The format of the package definition, usually using the company domain name Flashback output way COM (Enterprise Company). TZ (company name). util (Business module name) package definition format: Company domain name flashback. Project Name . module Name 5. The full class name is 6 with the package name. How to run the program with the package structure; Java com.tz.javase.pak.Student Java class loader behind the class name Jav The compiler behind the AC Java is followed by the path*/Package Com.tz.javase.pak; Public classstudent{ Public Static voidMain (string[] args) {System. out. println ("It's great! "); }}//import com.tz.javase.pak.*; Import all the classes inside the Pak//The import statement can only appear under the package statement, above the class definitionimport Java.util.date;import com.tz.javase.pak.Student; Public classtest01{ Public Static voidMain (string[] args) {//Sun-provided dateDate d =NewDate (); System. out. println ("Date:"+d); //com.tz.javase.pak.Student s = new com.tz.javase.pak.Student ();Student S=NewStudent ();//this calls the Com.tz.javase.pak below the student here to put the class in the folderCom.tz.javase.pak below;
System. out . println (s);} }
The Java access level modifiers mainly include: Private protected Public , you can qualify other classes for use of the class, properties, and methods. Note the following modifications to the class are only:publicdefault , except for inner classes
Package com;/*Modifiers on Access control permissions: Decorated class, adornment method, modifier variable private can only access the default in this class: This class, the same package, the other not protected this class, the same package, the subclass can be accessed, different packages do not; p Ublic can be any location*/ Public classuser{//class user can only use public or default//protected Retouching protectedString name; //default intAge ; }//Default Classclasstestming{ Public Static voidMain (string[] args) {User u=NewUser (); System. out. println (U.name); System. out. println (U.age); } }
Package Tz;import com. User; Public classtest{ Public Static voidMain (string[] args) {User u=NewUser (); //System.out.println (u.name);//protected RetouchingSystem. out. println (U.age);//default }}
Section 17th (is-a, is-like-a, HAS-A, package and import)