Java Basic Course Learning notes (10)

Source: Internet
Author: User
Tags modifiers

Knowledge Essentials: Athlete and coach case studies 1: Problems with formal parameters and return values (understanding)(1) Formal Parameters: Class Name: Object abstract class name required for this class: Subclass object Interface Name required for this class: implementation class object that requires the interface (2) return value type:Class Name: Returns the object abstract class name of the class: Returns the Subclass object interface name of the class: the object that returns the implementation class of the interface (3) a chained programming object. Method 1 (). Method 2 () ...   Method N ();      This usage: In fact, after the invocation of Method 1 (), it should return an object, 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 the folder (2) Role: A: Distinguish the same name Class B: Class classification management A: According to the function of B: According to the module (3) The definition of package (master) package name; Multi-stage packet. Separate. (4) Precautions : (master)The A:package statement must be the first valid statement in the file B: In a Java file, there can only be one package C: If the package is not available, the default is the non-packet name (5) The compile and run a: manual A: Write a Java file with a package.   B: Compile the Java file with the Javac command.   C: Create the package name manually.     D: Put the B-step class file to the bottom of the C-step package E: Go back to the same directory where the package root directory is and run with the package.   B: Automatic Type A: Write a Java file with a package. B:javac compile time with the-D can be javac-d. Helloworld.java c: Go back to and package root directory in the same directory where, and then run with package run. 3: Guide Pack (Master)(1) We use a class with a package many times, very troublesome, this time, Java provides a keyword import. (2) Format: Import Package name ...  Class name; Another: Import package name ... *;(not recommended) (3) Order of Package,import,class ( #面试题 #) Package > Import > Class 4: Permission modifier (master)(1) Permission modifier

Public

Protected

Default

Private

In the same class

Same bun class, other class

different bun types

Different packages other classes

(2) These four permission modifiers can only appear at any one time. public class Demo {} 5: Common modifiers (understanding)(1) Category: Permission modifier: Private, default, protected,public State modifier: static,final abstract modifier: abstract (2) common classes and their composition of adornments class:Default, Public,final,abstract common: public member variables:Private, default, protected,public,static,final common: private Construction Method:Private, default, Protected,public common: public member Methods:Private, default, Protected,public,static,final,abstract Common: public (3) also more common: public static final int X = 10; (Static constant) publ IC static void Show () {} (static method) public final void Show () {} (final method) public abstract void Show (); 6: Inner Class (understanding)(1)The 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. (2) access rules for internal classesA: The inner class can access the members of the external class directly, including the private. B: External class to access internal class members, you must create an object (3) classification of inner classesA: Member Inner class B: Local inner Class (4) member Inner classA:private for the security of the data b:static for accessibility (note: Static can only decorate the inner class and cannot be decorated with external classes) the member inner class is not static: The external class name . Internal Class Name Object name = new External class name. New internal class name (); the member inner class is static: The external class name . Internal Class Name Object name = new External class name. Internal class name ();(5) question of the inner class of the member (fill in the blanks)30,20,10 class Outer {public int num = 10;       Class Inner {public int num = 20;          Public Viod Show () {int num = 30;     SYSTEM.OUT.PRINTLN (num);     System.out.println (This.num); System.out.println ( NewOuter (). Num); System.out.println ( Outer.this.num); }}} (6) local inner class members of external classes can be accessed directly You can create an inner class object that invokes an inner class method through an object to use the local inner class functionality A: Local internal class access local variables must be final decorated. (#面试题 #)B: Why?   Because local variables are called with the invocation of a method, the data of the heap memory does not disappear immediately as the call is complete.   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. (7) Anonymous inner class (master)A: A simplified form of a local inner class B: the premise there is a class or interfaceC: Format: New class name or interface name () {override method; } D: Essence: is actually a subclass of anonymous objects that inherit the class or implement an interface(8) The use of anonymous internal classes in developmentWhen we develop, we see abstract classes, or interfaces as parameters.  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. (First of all, the formal parameters of the method we've talked about are reference types, and the focus is on the interface, and we know that a subclass object is needed here.) The anonymous inner class is a subclass of anonymous objects, so you can use anonymous inner classes to improve previous practices.  ) interface Person {public abstract void study ();   } class Persondemo {public void method (person p) {p.study ();    }} class Persontest {public static void main (string[] args) {persondemo PD = new Persondemo ();     Pd.method (new person () {public void study () {System.out.println ("Good study, day up");   }    }); }  } (9) Anonymous inner class of face question (completion code)Interface Inter {void Show (); } class Outer {//Complement code public static Inter method () {return new Inter () {public void Show () {SYSTEM.O     Ut.println ("HelloWorld");   }    }; }} class Outerdemo {public static void main (string[] args) {Outer.method (). Show ();//"HelloWorld"}}

Java Basic Course Learning notes (10)

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.