Java Learning Day

Source: Internet
Author: User
Tags modifiers

1: Problems with formal parameters and return values (understanding) (1Formal Parameters: Class Name: Object abstract class name required for this class: Subclass object Interface Name required for this class: An implementation class object that requires the interface (2return value type: Class Name: The object of the class is returned abstract class name: Returns the Subclass object interface name of the class: the object that returns the implementation class of the interface (3) Chained programming objects. Method 1 (). Method 2 () ....                Method N ();                  This usage: In fact, after the invocation of Method 1 (), an object should be used, and after the Call of Method 2 (), an object should be returned. After the method n () call is complete, the object may or might not be an object. 2: Package (understanding) (1) is actually a folder (2) function: A: Distinguish Class B: Classify the Class A: according to the function B: According to the module (3) package definition (master) Packagepackage name;    Multi-stage packet. Separate. (4Note: (master) The A:package statement must be in the file of the first valid statement B: In a Java file, there can only be one package C: If there are no packages, the default is the non-packet name (5) with package compile and run A: Manual type B: Automatic (Master) Javac-d. Helloworld.java3: Guide Pack (Master) (1we use a class with a package many times, very troublesome, this time, Java will provide a keyword import. (2) Format:ImportPackage Name ...        Class name; Another type of:ImportPackage Name ... *;(not recommended) (3) Package,Import, the Order of class Package>Import>class4: Permission modifier (master) (1The permission modifier into the subclass under different packages under a package under different packages of unrelated classesPrivatey default y yprotected y y y PublicY-y y y (2these four permission modifiers can only appear at any one time.  Public classDemo {}5: Common modifiers (understanding) (1) Category: Permission modifier:PrivateDefaultprotected, PublicStatus Modifiers:Static,Finalabstract modifier:Abstract    (2) Common classes and their constituent modifiers: default, Public,Final,Abstractcommonly used for: Publicmember variables:PrivateDefaultprotected, Public,Static,Finalcommonly used for:PrivateConstruction Method:PrivateDefaultprotected, Publiccommonly used for: Publicmember Methods:PrivateDefaultprotected, Public,Static,Final,Abstractcommonly used for: Public    (3In addition, more common: Public Static Final intX = 10;  Public Static voidShow () {} Public Final voidShow () {} Public Abstract voidShow ();6: Inner Class (understanding) (1The class is defined inside another class, which is called an inner class.    Example: Class B is defined in Class A, and Class B is called an inner class. (2access rules for internal classes A: You can access members of external classes directly, including private B: external classes to access internal class members, you must create an object (3the Class A: member Inner class B: Local inner Class (4) member internal class A:Privatefor the security of the data B:Staticin order to access the convenience member inner class is not static: the outer class name. Internal class Name Object name=NewThe external class name.Newinternal class name (); The member inner class is static: The outer class name. Internal class Name Object name=Newexternal class name. Internal class name (); (5) members of the inner class of the question (fill in the blanks)30,20,10classOuter { Public intnum = 10; classInner { Public intnum = 20;  PublicViod Show () {intnum = 30;                    SYSTEM.OUT.PRINTLN (num); System.out.println ( This. Num); System.out.println (Outer. This. Num); }            }        }    (6Local inner class A: Local inner class access local variables must be final decorated. B: Why??because local variables are used to disappear, the data for heap memory does not disappear immediately.            So, the heap memory is still using that variable, and the amount of change is gone.            In order for the value to exist, the final decoration is added.    With the anti-compilation tool, we see that, when final is added, the heap memory stores the value directly, not the variable name. (7Anonymous inner Class (master) A: is a simplified form of a local inner class B: The precondition exists for a class or interface C: Format:Newclass name or interface name () {override method; } D: Essence: A subclass of anonymous object that inherits the class or implements the interface (8The use of anonymous internal classes in development we will see abstract classes, or interfaces as parameters when developing.        And this time, we know that what is actually needed is a subclass object.                If the method is called only once, we can use the format of the anonymous inner class to simplify. InterfacePerson { Public Abstract voidstudy (); }                classPersondemo { Public voidmethod (person p) {p.study (); }        }                classPersontest { Public Static voidMain (string[] args) {persondemo pd=NewPersondemo (); Pd.method (NewPerson () { Public voidStudy () {SYSTEM.OUT.PRINTLN ("Good study, day up");            }                }); }        }            (9) Anonymous inner class face question (completion code)InterfaceInter {voidShow (); }                classOuter {//The code is padded             Public StaticInter Method () {return NewInter () { Public voidShow () {System.out.println ("HelloWorld");            }                    }; }        }                classOuterdemo { Public Static voidMain (string[] args) {Outer.method (). Show ();//"HelloWorld"            }        }

Java Learning Day

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.