Brief descriptions of classes and objects, brief descriptions of class objects

Source: Internet
Author: User

Brief descriptions of classes and objects, brief descriptions of class objects

First, open your mind

 

 

I. Based on the trend of Mind Map, there are four small points between classes and objects. First, let's talk about the relationship between classes and objects.

01: Why do we need to adopt object-oriented thinking for program design and development?

To put it bluntly, it is to make it easier for the program to respond to demand changes and reuse code.

02: Definition of classes and objects .......

001. class Definition: the Key modifier of class is called class.
002. object definition: data type defined by class name.

03: Relationship between classes and objects.

Is the process of summarizing objects into classes,

On the basis of the class, the process of instantiating the state and behavior into objects is finished.

Ii. Continue. Class and object definition class.

01: syntax of the definition class. The class is mainly composed of member variables and member methods (the constructor is not mentioned for the moment.

Public class Student
{
// Member variable
Int num = 0;
Private void Show ()
{
// Method body
}
}

02: member variables define the attributes of the class, and member Methods define the behavior of the class

3. Create an object;

There is an important new operator,

01 object creation process;

I am not very familiar with the narrative either. I just want to learn from other people's stories. <( ̄ ︶)>

When we allocate space. It should be noted that the allocated space is not only the space for allocating sub-classes, but also the space required by the parent class object contained in the sub-class object. When the space is allocated, all attributes are set to the default value.

It also recursively constructs parent class objects.

The next step is to initialize the attributes of this class. Call the constructor of this class.

Last, that is, 4: member variables and local variables;

01: A member variable of a class, also known as a field;

02: This section describes the scope of variables and the definitions and differences between member variables and local variables;

001 let's talk about the scope of the variable.

Public class TestScope
{
Public TestScope ()
{

// SA is valid within the TestScope () method.
String [] sA = new string [5] {"H", "e", "l", "l", "o "};

// Block scope: s6 is only valid within the foreach loop.
Foreach (string s6 in sA)
{
Console. WriteLine (s6 );
}

// S6 cannot be referenced here
// Console. WriteLine (s6 );

// You cannot redefine s6.
// String s6 = "";
}
}
002 definitions and differences between member variables and local variables;

<1> A local variable can be defined within a method.

Local variables do not have access permission modifiers and cannot be modified using public, private, or protected. This is because it can only be used within the method that defines it.

Local variables cannot be modified using static instead of "static local variables", which is a subtle difference between Java and C/C ++.

The system does not automatically assign initial values to local variables, but the system automatically assigns initial values to member variables. The value of the basic type is 0, and the value of the composite type is null.

Local variables with the same name are not allowed in the same method. In different methods, local variables with the same name may exist, and they do not interfere with each other.

<2> the member variable is the variable defined in the Variable Section of the class body, also known as a field.

Instance variables, class variables, and constants all belong to member variables ......

A member variable is also called a global variable. It is defined in the class and is at the same level as the class method. The member variable is equivalent to the number receiving machine in the bank, which can be used by anyone in the bank.

03: Finally, the concept of value type and reference type is :::::

1. Value Type
Resolution: The value type is derived from System. in the ValueType family, dou has an independent memory domain for each value type object to protect its own value. The memory region of the value type data becomes a Stack)
2. reference type,
Resolution: The reference type is derived from the System. Object family.

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

For more information, see the next "2 value type and reference type )/~~ Bye bye

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.