Briefly describe classes and objects

Source: Internet
Author: User

First, let's start with a mind map to open an appetizer.

A: According to the trend of mind map, class and object has four small points, we first say the relationship between class and object .

Why should we use object-oriented thinking for programming and development ?

Plainly, it is to make it easier for the program to respond to changes in demand. Implements code reuse.

the definition of classes and objects ....

001. Class definition: Class-Key-Modified
002. Definition of the object: the data type defined by the class name.

03: Relationship between Class and object.

Is that the object is summed up as a class, it is the process of inductive object generality,

There is also the process of instantiating state and behavior into an object based on the class,,, is done.

Second: Go ahead, class and object definition classes.

01: Define the syntax of the class, the class is mainly composed of member variables and member methods (not to mention the constructor) .... Defines the syntax of a class for short.

public class Student
{
Member variables
int num = 0;
private void Show ()
{
Method body
}
}

02: Member variables define the properties of the class, member methods define the behavior of the class

Three: Create objects;

There is an important new operator,

01 The creation process of the object;

I'm not too good at narration, just learn from someone else's passage.,< ( ̄︶ ̄) >

When we allocate space. It is important to note that allocating space is not only the space allocated for the subclass, but the space required for the parent class object contained in the subclass object, which is uniformly assigned in this step. When allocating space, all properties are set to their default values.

There is also a recursive construction of the parent class object.

This is followed by the initialization of this class of properties. Call the constructor method of this class.

Finally, four: member variables and local variables;

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

02: Introduce the scope of variables and explain the definition and difference of member variables and local variables;

001 first say the scope of the variable.

public class Testscope
{
Public Testscope ()
{

SA is valid inside the Testscope () method.
string[] SA = new String[5] {"H", "E", "L", "L", "O"};

Block scope: The S6 is only valid inside the Foreach loop.
foreach (String s6 in SA)
{
Console.WriteLine (S6);
}

You can't refer to S6 here.
Console.WriteLine (S6);

Also cannot redefine S6
String s6 = "";
}
}
002 The definition and difference of member variables and local variables;

<1> the so-called local variables are variables that can be defined inside a method.

Local variables do not have access modifiers and cannot be decorated with public, private, and protected. This is because it can only be used inside the method that defines it.

Local variables cannot be modified with static, and there is no "statically local variable", which is a subtle difference between Java and C/D + +.

The system does not automatically assign initial values to local variables, but for member variables, the system automatically assigns initial values. The value of the base 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 of the same name can be used, and they do not interfere with each other.

<2> a member variable is a variable, also known as a field, that is defined in the variables section of the class body.

instance variables, class variables, constants belong to member variables ...

anyway , a member variable is also called a global variable, defined in a class, and the method of a class is at the same level. Member variables are equivalent to the number of machines in a bank and can be used by people in a bank

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

1. Value types
Parsing: Value types originate from the System.ValueType family, and each value type's object dou has a separate memory domain for protecting its own values, and the memory area where the value type data resides is the stack (stack)
2. Reference types,
Parsing: The reference type originates from the System.Object family.

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------

For information on how to do this, please follow the next "2 value type and reference type", OK, So, (^_^)/~~ bye

Briefly describe classes and objects

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.