Diff. B/w Imports & Inherits?

A

Arpan

What's the difference between "Imports" & "Inherits"? For e.g. both the
codes below work without any errors:

Imports System
Imports System.Data
Imports System.Web.UI

Namespace Constructors
Public Class Constr : Inherits Page
Public Sub New()
Response.Write("Constructor1")
End Sub
End Class
End Namespace

----------

Imports System
Imports System.Data

Namespace Constructors
Public Class Constr : Inherits System.Web.UI.Page
Public Sub New()
Response.Write("Constructor1")
End Sub
End Class
End Namespace

In the first code snippet, I am importing "System.Web.UI" & then
inheriting the "Page" class where as in the second code snippet, I am
just inheriting "System.Web.UI.Page". So what's the difference between
importing & inheriting?

Thanks,

Arpan
 
S

Sean Chambers

Imports just allows you to not have to type out the namespace that
contains the class every single time. So, by declaring Imports
System.Web.UI, and then doing Page, it knows which class you want,
without using the Imports statement, you would have to type out
System.Web.UI.Page everytime.

the "Inherits" keyword is completely unrelated. This has to do with
Object Oriented Programming and one of its many features. Search for
OOP on wikipedia.org, as this topic as a whole is out of the scope of
this thread.

Hope this helps!

Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top