Java Fundamentals (10) Object Oriented (v)

Source: Internet
Author: User
Tags modifiers

Here are some of the lessons I summarized in the previous lesson and the code is most of the teacher's notes personally think is very good, but also a more classic content, sincere hope that these for those who want to learn some help!

Because the code is sub-module upload is very inconvenient. Also more, speak of is more clear! If you need to be able to leave your email in the comments I see will be sent to you for free! Thank you for this platform let us all progress together!! Remember that the programmer is selfless!!!

Also very welcome to my blog to watch the blog address: http://www.cnblogs.com/duscl/

/*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: The Implementation class object (2) that requires the interface returns a value type: Class Name: Returns the class Object abstract class Name: 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 (), 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) In fact is 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 the package (master)                Package name;    Multi-stage packet. Separate.         (4) Note: (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 compilation and run A: Manual type B: Automatic (Master) javac-d.    Helloworld.java 3: Guide Pack (Master) (1) We use a package class 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) Package,import,class sequence Package > Import > Class 4: Permission modifier (master)     (1) Permission modification into similar to the sub-class under different packages under a package of unrelated classes under different packages   Private y default y y protected y y y public y        Y y Y (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                Abstraction Modifiers: abstract (2) common classes and their constituent modifiers: default, Public,final,abstract common: public Member variables: Private, default, protected,public,static,final common: private structure Build method: Private, default, Protected,public Common: Public member Method: Private, Default, p Rotected,public,static,final,abstract Common: Public (3) also more common: public static final int X =        10; public static void Show () {} Public final void Show () {} public abstract void Show (); 6: Inner Class (understanding) (1) defines a class in another        Within a class, the class 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 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 (3) Class A: member Inner class B: Local inner Class (4) member inner class a:private        For the security of the data b:static the inner class of the convenience member in order to access is not static: the outer class name. Internal class Name Object name = new External class name. New internal class name ();    The member inner class is static: The outer class name. Internal class Name Object name = new External class name. Internal class name ();                        (5) The 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 (Outer.this.num);        }}} (6) Local 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. (7) Anonymous inner class (master) A: YesSimplified form of local inner class B: If there is a class or interface C: Format: New class name or interface name () {override method;        } D: The essence: A subclass that inherits the class or implements an interface anonymous object (8) Anonymous inner class in development use when we are developing, we will 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.        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) The face question (completion code) of the anonymous inner class interface Inter {void Show (); } class Outer {//Padded code public static Inter method () {return new Inter () {public void Show () {System.out.println ("                    HelloWorld ");            }                    }; }} class Outerdemo {public static void main (string[] args) {Outer.metho D (). Show (); "HelloWorld"}}*\

Java Fundamentals (10) Object Oriented (v)

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.