"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