C # Object-oriented programming encapsulates inherited polymorphism

Source: Internet
Author: User

C # Object-Oriented programming

what is Object-oriented ?

Object-oriented programming is a new programming idea proposed by the last 60 's after the structure-oriented programming.

Encapsulation, inheritance, polymorphism

Encapsulation, inheritance, polymorphism is the core of object-oriented programming:

Encapsulation is the first step in implementing object-oriented programming, in which a collection of data or functions is set in a unit (what we call a Class). Encapsulated objects are often referred to as abstract data types

The meaning is: protect the data is not destroyed (for example a TV we can use it but can not arbitrarily change the internal circuit)

Keyword: private,public,protected,internal

public string name;

Inheritance : The main implementation of the inheritance code reuse, save development time in the inheritance of the constructor run order from top to bottom and the destructor is the following, the inheritance statement is as follows:

public class Name: class name

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

When learning polymorphism, you have to mention the virtual method

Virtual method: The method of declaring virtual is a virtual method that defines a virtual method in a base class that can be overridden in a subclass using override

And the process of using rewriting is polymorphic

Virtual public void show ()//define virtual methods

Override public void show ()//rewrite of the method

Base Key Words

Base Keyword:the base keyword is used to access base class members from derived classes The main form is as follows:

Calling a method on a base class that has been overridden by another method

Specifies the base class constructor that should be called when creating an instance of a derived class

(the base keyword cannot be used in a static method)

I wrote here a case of a demonstration

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Inheritance of namespace code

{

Class goods//defines a base class

{

public string Tradecode {get; set;} Define Product number

public string FullName {get; set;} Define the product name

}

Class Jhinfo:goods

{

Define the purchase number

public string Jhid {get; set;}

public void Showinfo ()//Output Stock Number

{

Console.WriteLine ("Arrival number: {0}\n Product code: {1}\n Product name: {2}\n", jhid,tradecode,fullname);

}

}

}

Class Program

{

static void Main (string[] args)

{

Jhinfo JH = new Jhinfo ();//Instantiation of Object

Jh. Tradecode = "Ares 1000";

Jh. FullName = "notebook computer";

Jh. Jhid = "ZS10000";

Jh.showinfo ();

Console.WriteLine ();

Console.readkey ();

}

}

}

C # Object-oriented programming encapsulates inherited polymorphism

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.