Classes and objects

Source: Internet
Author: User

The class is abstract;

The object is specific;

A concrete instance of a class is an object;

The object belongs to a class.

Example: "Notebook Computer Class" is a class; "Your laptop" is the specific one in "laptop class", so "your laptop" is an object of "laptop class".

"Notebook Computer Class" describes the characteristics of all laptops; "Your laptop" has its own unique features in addition to the shared features of laptops.

"Notebook Computer class" is an abstract description of the characteristics of the notebook computer, not the only correspondence to a laptop computer.

The objects of classes and classes are 1:n relationships.

Create a class using the class keyword

Class Computer

{

Describe the characteristics of a class

}

Use the members of a class to describe the characteristics of a class, that is, properties and methods.

Classes and objects are inseparable, and in C # The class is instantiated with the keyword new, creating an object

Example:

Computer computer = new computer ();

Create a class:

Example:

Computer

+cpu

+ Memory

+ HDD

+ Display

+ Internet ()

+ Play games ()

+ Office ()


(class name)

Properties

Method

attributes can be represented by variables and represented;

The act is expressed by means of a method;

To create a member variable:

Scope: public, which can be accessed directly when an instance of the class is created.

Private, where member variables are accessible only within the class, which is usually the case for methods in the class.

To create a method:

[Scope] Return type method name (parameter)//method parameter in four types, specific reference method in the parameters of an article

{

Method body

}

Example:

Class Computer

{

   public i;

   public void Get ()

{

return 0;

}

}

Computer computer = new computer ();

You can pass the object name. The variables and methods of the class are called in the way [variable | method name].

Example:

computer.i = 0;

Computer.get ();

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.