Array object-oriented member variables and local variable amount differences

Source: Internet
Author: User
Tags access properties

I. Arrays 1. Common Errors in arrays:

1.NullPointerExcepation: null pointer exception

Cause: The referenced type variable does not point to any object, in which case it also accesses its properties and methods.

An object will not be released immediately if it is used, but it will be turned into a garbage object and freed by the garbage collection mechanism itself. , we have no way to operate it to release.

2.ArrayIndexOutOfBoundsExcepation: Array The following table is out of bounds.

Two. Object-oriented 1.java also belongs to object-oriented programming: 2. Object-oriented three major features: encapsulation, inheritance, polymorphism. Class, Object. 3. Object: The only thing that really exists. 4. Object-oriented programming (OOP) ideas try to make the description of things in computer languages as consistent as possible with those in nature. 5. Object-oriented core: Find the right object to do the right thing. How to find the right object in 6.java:

1.sun classes are already assigned, and you need to know these classes to create objects from custom-made classes.

2. Customize the class to create the object from the custom class.

7. The class contains: properties, methods. 8. The definition format of the class:

Class Name {

Attribute (member variable): Describes the public characteristics of a thing.

Method: Describe the behavior of a thing (what to do)

}

9. Create an object from a custom class

Format:

Class Name Object name (variable name) = new class name ();

Access Properties:

Object. Property name

To set properties:

Object. property name = data.

method to invoke the object:

Object. Method name ();

10. Relationship of classes and objects:

A class is an abstraction of the same class of things (objects) that the object actually exists for various entities of that class.

Three. The difference between the member variable and the local variable amount: 1. Location defined:

1. Defined in the class, outside of the method.

2. Local variables are defined in the method.

2. On the effect:

1. Member variables are public properties used to describe the same class of things (objects).

2. A local variable is to provide a variable for the method to use

3. Life cycle:

1. The member variable is created as the object is created and disappears as the object disappears.

2. Local variables are created as a method call, and the scope of the method disappears.

4. Initial values to differentiate:

1. Member variables, if you do not assign a value, it has a default value.

int by default is 0

Float default is 0.0f

Double default is 0.0

Boolean Default False

Char default ' '

String (reference type) null;

2. Local variables:

A local variable has no initial value and must be initialized before it can be used.

5. Member variables can be used directly from the variable name in the current class, and if the variable needs to be used in other classes, the object needs to be created (as it is now)

Array object-oriented member variables and local variable amount differences

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.