Construction methodconstructor method, which is the same as the class name and has no return value, without voidThe main function of the construction method is to create the object and assign the initial value to the objecta construction method without parameters is called a default constructconstruction methods can be overloaded with parameters, if you want to assign specific initial values to an objectyou can write a constructor with parameters in the class and callIf there is no construction method inside the class, when we create the object, the system automatically generates a default construct for useif the class has a constructor with parameters, the default construct must be displayed by writing the default construct when it is called Object-oriented three major features: encapsulation, inheritance, polymorphismPackagewhen we create an object, we do not want the external human to destroy the value of the field contained in the object, then we need to encapsulate the data .This is done by decorating the member field with the private field so that the external cannot get the field and modifies the stored dataat the same time, the private field is changed to a property, the value of the field is modified by the property, the object is created and the object is initialized .You can assign an initial value to a field with a constructor method with parameters, write the field as private, although it cannot be used externally, but can be used inside the class ,that is, a method inside a class can invoke a private field inside a classInheritancewhen a subclass inherits the parent class, it inherits the members of the parent class .the members of the parent class, if they are decorated with public, are called common inheritance, and are called private inheritance with private adornments .members of public inheritance can be used everywhereA private inherited member can only be used within a taxonomy and cannot be used on extra faces of a classprotected inherited members can only be used within the parent class and subclasses, and cannot be used outside the class.//Richter conversion Smalldog small = New Smalldog(); BigDog big = New BigDog();Stu. Walkdog (big);Stu. Walkdog (small); //When processing data, in order to achieve a uniform type of data being processed , //The type of the data is uniformly written as the type of the parent class, so that the object of the subclass can be assigned directly to the parent class /////The first principle of the Richter conversion: To assign a value to the parent class object, but invoke the member inside the class can only call the parent class inside the child class inside the call not to Dog dog = small; /////The second principle of the Richter conversion; Turn the object of the parent class into a subclass, as BigDog s =dog as BigDog; if (s!=NULL ) {S.bigdogbark (); }//The process of converting a value type to a reference type is called boxing Object obj = A; Console. WriteLine (obj); //Convert a reference type to a value type called a unboxing int c= (int ) obj; polymorphicVirtual override
C # Notes (ix)--Object oriented