Object-oriented and Object-Oriented Programming
I only know about object-oriented knowledge, but it is not enough to fully apply it to projects.
1: Simulate items and attributes in the world through code in the program.
It is the unique feature of an object ). An object is a real and specific item.
2: attribute ----- feature method ---- Behavior
A class is the embodiment of object commonality. A class is a template. It determines the characteristics (attributes) and behavior (methods) that an object will possess. It reflects the common attributes of an object;
3: A class is an object type. If an object can be declared by a class, the object will have its attributes and methods. A class is a concept and an object is a kind of object; [compare the concepts and struct of classes, so that we can understand them very well]
4: Class instantiation uses classes to declare objects. classes do not occupy memory while objects occupy memory;
5: Define the statements of the class (the class file ends with ". cs)
(Access modifier) class name
{
Statement member of the class;
}
* A class is defined in a. cs file. do not define multiple classes in A. cs file.
* The first letter of the class name is capitalized;
6: Class instantiation is implemented when an object is generated through classes.
Class Name object = new Class Name ();
Class Name zeSan = new Class Name ();
This object (zeSan) has such attributes and behaviors.
7. assign values using "Instance name. Attribute", while "Instance name. Method" is called for display;
//////////////////////////
1: statement about adding static to methods [Key]
* Add static. In main, this method can be called using "class. method name" ("class name. Attribute or class name. Method ");
* Without static, this method must be instantiated in main before it can be called ("Instance name. method or Instance name. Attribute ");
* This is also different in memory allocation;
2: Use classes for instantiation. They exist in different memory spaces, so that no matter which one you modify, nothing else will be affected;
3:
Access modifier: There are four access Modifiers
* Public: it can be accessed anywhere;
* Private: It can only be accessed in this class. (default value)
* Preotected: It can only be accessed in this class and subclass;
* Intemal: It can only be accessed in this project;
4: assign a value to a variable. You can write a field as a method to assign a value. The field is accessed and called externally;
5: The attribute is the defined public variable that contains the get and set methods;
The set method is used for value assignment; the get method is used for value assignment;
You can determine in the set Method to see if it is the required input value.
Attribute is used to protect the validity of private fields;
6: Read-only attribute. Delete the set Method and leave only the get method. This attribute can only be read and cannot be written;
///////////////////////////////
1: When a class is initialized, if it is not assigned a value, the system will automatically initialize it;
String Initialization is NULL;
Char initialization: \ 0;
2: constructor benefits
* When you do not need to assign values to multiple attributes, you do not need to repeatedly write instance names;
* Ensure that users must assign values to new users.
* Initialize the read-only attribute when creating an object.
3: after the class is defined, the system automatically defines a constructor, but we cannot see it;
4: Constructor
* Features: no return value. The method name and class name are the same;
You can use the constructor to define the value through parameters, such as the read-only "name", "ID", and "ID;
//////////////
Constructor is a special member method. Its particularity is reflected in the following aspects:
1. Role of the constructor:
(1). Construct an instance of the class (2). initialize the instance (object) of the constructed class.
2. the constructor name must be exactly the same as the class name defined for the constructor. No return type, or even void.
3. the initialization of objects is completed. The constructor calls the new operation when creating an object.
4. There must be a constructor in the class. If no constructor is written, the system automatically adds a constructor without parameters. The interface cannot be instantiated, so there is no constructor in the interface.
5. It cannot be modified by static, final, synchronized, abstract, or native.
6. the constructor is automatically executed during object initialization and cannot be called explicitly. when multiple constructor methods exist in the same class, the java compilation system automatically corresponds to each other based on the number of parameters and parameter types in the last square brackets during initialization. Call the constructor.
7. There are two constructor methods: the construction method without parameters and the Construction Method with parameters.
The constructor can beHeavy Load. The constructor without parameters is calledDefault constructorThe constructor can perform any activity like a general method, but it is often designed to perform various Initialization activities, such as initializing object attributes.
8. Construct a code block:
(1) Purpose: Initialize the object, and execute the object as soon as it is created, and take precedence over the constructor execution.
(2) differences between constructing code blocks and constructors:
The constructor code block initializes all the commonalities of different objects. The constructor initializes the corresponding objects.
9. Subclass inherits from the parent class,
* ** Subclass instantiation Process
* ** The constructor cannot inherit from the quilt class.
* ** When a subclass creates an object, it first creates the object of the parent class.
The default method is to call the non-argument constructor of the parent class.
* ** In the subclass constructor, the first line defaults to super ()
* ** Why is super () exists in the first line of the subclass by default ()
Because it inherits the use of members of the parent class, these Members must be initialized before use,
They are members of the parent class. Therefore, they must be initialized through the parent class.
Therefore, an object of the parent class is created first.
** When the parent class does not have a construction method without Parameters
You must use this or super to call other constructor methods.
10. In a custom class, if no constructor is written, the java System will add a constructor without parameters by default. If you have written a constructor with parameters, you do not need to write a constructor without parameters.
To use a construction method without parameters, you must manually provide a construction method without parameters.
Suggestion: Generally, we need to manually provide a construction method without parameters for custom classes.
////////
1: to instantiate a class, you must call its constructor. The constructor can have multiple parameters;
2: constructor methods can be overloaded or have constructor methods with multiple parameters;
3: class chart
4: sufficient analysis functions (the method called when the GC Garbage Collector collects garbage)
* Only One destructor can exist in a class;
* Unable to inherit or overload
* It cannot be called automatically;
5: To throw an exception syntax
Throw new exception ("exception prompt ");
1: Any type can be converted to the object type. You can call the function by converting to the definition to view your variables;
2: console. writeline (); is a function call;
3: (variable array) add params in front of the array to directly add elements to the array. Each element is separated by commas;
4: The params keyword specifies that the parameter method parameter is used when the number of parameters is variable. After the params keyword in the method declaration, no other parameters are allowed, and only one params keyword is allowed in the method declaration.
***********
1: Class Folder: namespace)
* It is mainly used to solve the cognominal problem of classes;
* It is equivalent to the folder format and is easy to understand;
2: Call. Access under different namespaces
* Write the full namespace. Class Name
* Using references the namespace before calling it;
3: You can only access the classes in your namespace. You cannot access the classes in different namespaces. To access the classes in different namespaces, you must reference "using. namespace name"
4: All namespaces are under the system namespace, and Other Namespaces can be defined under the namespace; system is the root namespace;
5: The namespace can be named as the name of your own company, which is defined repeatedly for future code;
/////
1: The c language uses char arrays to store strings, while the c # string is used to define strings, which are actually stored in arrays. Strings can be considered as arrays; [string is a special type]
2: Once a string is declared as a value, it cannot be changed. It should be read-only. (immutable)
3: Class Method
How to modify the string value
String s = "hello word ";
Char [] chars = s. ToCharArray ();
S = new string (chars );
Console. writeline (S );
4: The method indicates the action, and the attribute indicates the State;
*******
The writing is messy and there are no rules. It is easy to review the knowledge later.
*******