Encapsulation and static--of three characteristics of object-oriented (Java Learning Note IV)

Source: Internet
Author: User

Object Oriented Programming Essence: Organizing code in a class, organizing (encapsulating) data in an object way
Object : A specific thing, an object (instance) class of a class: An abstraction of an object that describes an abstract concept of an object of the same type

Relationships between objects and classes: Special to general, concrete to abstract

Three major features: Encapsulating an inherited polymorphic constructor: Also called a constructor method (constructor), used to construct an instance format for a class: modifier class name (formal parameter list) {//statement} The constructor's method name and class name are called by the New keyword when a constructor method is not defined, the system customizes an parameterless constructor constructor that can be overloaded: constructs the object of the class, initializes the object's properties PS: Once the display writes a constructor, the default The method is not present static keyword: Features: Loading with a class takes precedence over the existence of objects that are shared by all objects can be called statically by the class name only can access static members, but non-static methods can access static members,static methods can not use the This,super keywordMethods or fields that do not use static adornments, which belong to an object, can be referred to as instance members using the static decorated method or field, belong to a class, and can be called a class member invocation: If an instance member: A field or method that is decorated with static, that is, a class member, can be called by using the class name. You can also use objects to invoke them. Because the object calls the class member at the bottom, it is also called to the class name, so use theClass name CallGood    there is an area in the JVM that is specifically used to store static decorated members called the quiescent storage area  static performance, because each time a class member is loaded to open up space and instance members only need to create space at the time of creation   Anonymous object:    features:        make only one call to a method or field         can be used as an actual parameter for delivery         Only opens up space in heap memory, not on stack memory references    One of three features encapsulates:        1 to consider the state and behavior of an object as a unified whole, storing both in a separate module (class) and nbsp       2 "information hiding", hiding information that does not need to be known to the outside world, hiding objects as much as possible to realize the details of the function, the field encapsulation mechanism is embodied in the program: the state of the description object is represented by a field, the description object behavior is represented by a method, and the field and method are defined in a class , and ensure that the outside world can not arbitrarily change its internal values, nor allow arbitrary transfer of its internal functional methods. One embodiment of the program: the privatization of member variables in a class (private); the privatization of member variables can be accessed by providing getter and setter methods externally. Getter method, which is used to obtain the value of the privatization variable.     Format:        "non-private modifier" field type get field name () {              &NBSP ;             return field name;               }setter method for setting The value of the privatized member variable     format:        "non-private modifier" void  set field name (field type   variable) {      &NBS P                       field = variable;               }

Encapsulation and static--of the three major features of object-oriented (Java Learning Note IV)

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.