Lan Unity Development Fundamentals Two-Class 4 classes and objects

Source: Internet
Author: User

"Lan Unity Development Fundamentals II "Class 4 classes and objects

First, classes and objects

Class: The function of a class is to classify

A class is used to abstract the characteristics and behavior of an object.

Classes are abstractions used to describe behaviors that have the same characteristics


Second, define a class

Define a new type using the class keyword

Access modifier Class class name {class member ...}

public class person{string name;}


Third, Object

A class is an abstract type, and an object is a concrete instance.

Person P =new person ();


class and object source codeusingSystem;

namespacelesson_04
{
    //define a Peerson class
     Public class  Person{
         Public stringName://Name
        
    }
     Public class Car{
        
    }
        

    class MainClass
    {
         Public Static voidMain (string[] args)
        {
            //Declare a variable with person p,p called object, initialized with new
            //objects are also known as instances of classes, and the process of creating objects using classes is also called instantiation
             Personp=New  Person();
             PersonP1 =New  Person ();
            CarC =New Car();

        }
    }
}

Recommended Video Lecturer blog:http://11165165.blog.51cto.com/


Exercise: Create 10 classes and create individual objects with these types, respectively;



Lan Unity Development Fundamentals Two-Class 4 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.