Java Learning Diary NUM4

Source: Internet
Author: User

Learning Content : Object-oriented overview; encapsulation; constructors to construct blocks of code; the This keyword; some other points of knowledge I. Object-oriented Overview 1, process oriented and object orientedThe process-oriented emphasis is on the function behavior, object-oriented is based on the process-oriented, the emphasis is on the function of an object, object-oriented is based on the process-oriented.  2, the difference between a class and an objectA class is a description of something in the real world, a description of the properties of the thing, and what functions it has. For example: The description of people, people with the name, age, hair color, gender, hobbies and other common attributes, as well as eating, sleeping and other common functions object is the real life of the individual. For example: A person named Zhang San, has the age name sex, can eat to sleep, in addition also has a call John Doe person, also has own name age sex and so on.  Second, package (encapsulation)1, Package conceptencapsulation refers to the properties and implementation details of hidden objects, and provides public access only externally. In other words, I give you the way you use it, you don't have to worry about how it is done, you just use it. 2, Encapsulation principleA, hide content that does not need to be provided externally.B, hide properties, provide public methods to access them3,private KeywordsPrivate Chinese meaning is proprietary, she is a permission modifier that is used to decorate members (member variables and member functions) in a class, and is only valid in this class for members that are privately decorated. It is important to note that encapsulation is not private, and private is only a common form of representation of encapsulation. Encapsulation is not equal to private. Functions, classes, and packages are also representations of encapsulation. third, constructor and construction code block 1, the characteristics of the structure functionA, the constructor is the same as the class nameB, the constructor does not return a value typeC, there is no return statement in the constructor 2, function of the constructorThe constructor is used to initialize the corresponding constructor, and the corresponding constructor is initialized when the object is created by the new operator, depending on the arguments in the incoming constructor 3, the difference between a constructor and a general functionA, the constructor is used to initialize the corresponding object. A general function is used to implement a particular function of an object. B, the constructor executes at the time the object is established and executes only once. A general function can be called multiple times by an objectC, there's a big difference in their wording . 4. Considerations for constructor FunctionsWhen a constructor is not defined manually in a class, in order to create an object of that class, the default constructor is added to the class by default, and when a constructor is customized in a class, the system does not add the default null argument constructor to the class, if the object is created , you also need the constructor of the null parameter, then you need to customize the constructor of the null parameter; there can be multiple constructors in a class, an object is created, and a constructor is called, which is implemented by overloading the constructor. 5, building blocks of code 1) format: {Constructs the initialization content of the code block} 2) function: To initialize all objects, constructs the code block to hold the common initialization content of the class object. The object runs when it is established, and takes precedence over the constructor function.      Four, this keyword 1,this The role of the keyword? The This keyword is used to differentiate between local variables and member variables, and also for mutual invocation between constructors in a class. The This statement must be placed on the first line when constructors in a class call each other.  meaning of the 2,this keywordThis represents the object of the class, which is the specific one? is the reference to the object to which the function belongs. Simply put: Which object calls this function, which is the object that this represents.  application of 3,this keywordWhen defining a function in a class, this is used to represent the object when the function is used internally to invoke the object. The use of this class object in this class is used whenever this v. Some other points of knowledge 1, the difference between a member variable and a local variablemember variables are defined in a class, scoped to the entire class, and stored in heap memory. A local variable is defined in a function or statement, and the scope is the function or statement in which it resides, and is stored in the stack memory .2, use of anonymous objectswhen an object needs to be used only once, an anonymous object can be definedan anonymous object can also pass past as the actual argument of a function.

Java Learning Diary NUM4

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.