Java Programming Ideas-2nd Chapter book notes

Source: Internet
Author: User
The 2nd Chapter: everything is the object
  • If a member of a class is a basic data type, Java ensures that it obtains a default value even if it is not initialized. For a "local" variable (that is, a field that is not a category), a value must be given before use, and if you forget to do so, Java will return an error at compile time to tell you that the variable is not initialized.
  • A is an object, and the int x=a.f(); return value must be compatible with the type of x. The behavior of this method of invocation is often referred to as sending a message to an object . Object-oriented programming is generally simply summed up to send messages to Objects .
  • If the return type is the Void,return keyword, the function is used to exit the method. Therefore, it is not necessary to leave at the end of the method and to return anywhere. However, if the return type is not void, the compiler will force return a correct return value regardless of where it is returned.
Static keyword
  • A domain or method declared with static has only a single storage space, which is not related to the number of objects, and all objects share such a domain or method. Instead of a static field, you have one storage space for each object.
  • When declaring a thing to be static, it means that the field or method is not associated with any object instance of the class that contains him. that is, the properties and methods declared with static belong to the class itself, not to the object . This static method can also be called when an object is not created.
  • Because you do not need to create any objects before using the static method, you cannot simply access other non-static fields or methods for the static method. (This is because a non-static domain or method must be associated with a particular object)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Programming Ideas-2nd Chapter book notes

Related Article

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.