Inheritance extends a new class based on an existing class. The new class inherits the members of the existing class and can add new members. An existing class is called a parent class or a base class, and a new class is called a subclass or a derived class. In VB. NET, one class can only have one parent class. Multiple parent classes are not allowed, that is, only single inheritance is allowed.
Syntax:
Class Name
Inherits base class name
Class member declaration
End Class
The preceding syntax declares a new class derived from the class indicated by the base class name. The "class member declaration" is a newly added member of the derived class, which can be an attribute or method. For example:
Class Manager
Inherits Employee
Public Sub PrintBonus ()
Reponse. Write (yearlyBonus)
End Sub
End Class
The previous example defines the sub-class Manager of the Employee class. In addition to inheriting all the members of its parent class, this class also adds a method member PrintBonus ().
ASP. NET server controls are constructed according to the class hierarchy method. All Server Control classes are derived from System. web. UI. control class, so all server controls have System. web. UI. control class attributes, methods, and events, and each server Control class adds its own attributes, methods, or events. For more information about server controls, see Chapter 4th.
| BibliographyPrevious sectionNext section |