We help IT Professionals succeed at work.

Subtype and enclosing type

william007
william007 asked
on
Medium Priority
816 Views
Last Modified: 2008-01-30
What is Subtype and enclosing type? What are their example?
Comment
Watch Question

Commented:
http://en.wikipedia.org/wiki/Subtype
A general type "Bird" can be subclassed into multiple subtypes (inheritance). They share all the information with Bird, but can define their own as well. Here is another example, with some code:
public class Person
{
    public string Name;
}

public class Employee: Person
{
    public int Salary;
}

Because Employee is a subclass (because C# uses classes they tend to be called subclasses instead of subtype) of Person it inherits the Name field, but also adds it's own Salary field.

http://msdn2.microsoft.com/en-us/library/tdz1bea9(VS.71).aspx
To define an enclosing type we must first look at nested types. A nested type is when a type is defined inside another type:
public class TextBox
{
    public class Scrollbars
    {
    }
}
Which you can then reference by using TextBox.Scrollbars. However, unlike namespaces TextBox can also have it's own information and you can create instances of both TextBox and TextBox.Scrollbars.
In this instance TextBox would be Scrollbars enclosing type.

Author

Commented:
Thanks:)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.