Java chapter Seventh Class and object notes

Source: Internet
Author: User
Tags java keywords

Java chapter Seventh Class and object notes

The characteristics of an object--the properties of a class each object has a specific value for each property

Operation of objects--Methods of classes

Second, the package: The object has both properties and methods two characteristics.
Object properties and methods are often encapsulated together to reflect the nature of things,
They are mutually reinforcing and cannot be divided.

Iii. differences between classes and objects:
Class: Abstract concept, is a mold that determines the properties and methods of an object.
Object: The kind that can be seen and touched. have static and dynamic characteristics.

Iv. steps to define a class:
1. Defining the class name
2. Define the class's property access Modifier Property Type property name = default value;
3. Define the method access modifier for the class return value type method name () {

Method body;
}


V. Member variables and local variables
Member variables: The ancestor is the class, the scope is the entire class
Local variables: The ancestor is the method, the scope is the current method

Six, class name naming rules:
1. Not using Java keywords
2. The first letter can be a letter, or it can be _ or $
3. Cannot contain spaces and punctuation


Vii. Creating objects: Keywords: new
Class Name Object name =new class name ();
Example: Yuntuschool beijing=new yuntuschool ();

Viii. use of objects: key symbols
The name of the object. Attribute = value; Beijing. Schoolname= "cloud-linked Beijing Center";

The name of the object. method; Example: Beijing.showinfo ();

Nine, the advantages of object-oriented:

1. Easy to program simulation of real-world entities
2. Hide details (encapsulation): The behavior and properties of an object are encapsulated in a class,
The outside world is obtained by invoking the methods of the class, without paying attention to how the internal details are implemented.
3. Reusable
You can create objects of multiple classes through the template of the class.

The class is the reference data type, when the value is passed, object 2 = Object 1, the address is passed, one change, and the other one is changed; object 2.name= Object 1.name

Java chapter Seventh Class and object notes

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.