Classes (but not structs) support the concept of inheritance.
A class that derives from the base class automatically has all the public, protected, and internal members of the base class except its constructors and destructors.
In C# one class can only inherit from a single class.
The following code defines a Person
class. Person
class has all common fields for all person
types.
class Person{
public string name;
}
When declaring the Employee
class we can build the employee type based on person type.
class Employee:Person{
public string companyName;
}
Employee
inherits the name field from Person
.
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |