|
-
Apr 18th, 2003, 10:48 AM
#1
Thread Starter
PowerPoster
Difference between Inherits and Imports
I noticed you can only Inherit one class per class. But you can Import all the classes you want. Don't Inherit and Import basically do the same thing?
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 18th, 2003, 10:52 AM
#2
Import is just a shortcut for namespaces. Inherit makes a class inheit the abilities of the inherited class.
They are completely different,
-
Apr 18th, 2003, 10:52 AM
#3
Fanatic Member
Absolutely Not!
Inheritance allows you to extend a class, while importing only gives you access to a class (or set of classes). Pick up any VB book or search the help - it will give you details.
Also, VS.NET 2003 does allow multiple inheritance.
-
Apr 18th, 2003, 11:22 AM
#4
Thread Starter
PowerPoster
I see, so Inherit is like just adding the methods of another class to your class and other people could then use all those methods as if it were a single class. So if i created a class called MyClass and added 2 methods and i imported another class that had 5 methods then i compiled it, if i were to create an instance of MyClass i would have access to all 7 methods.
Whereas if i Imported a class with 5 other methods i would have access to those inside my class but anyone using my class would not. I think that's it.?
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 18th, 2003, 11:36 AM
#5
Think of imports as a With statment. If everytime you want to show a message box for example.
Without an Imports:
system.Windows.Forms.MessageBox.Show("Hello")
if you add an Imports System.Windows.Forms, then all you need is
MessageBox.Show("hello")
-
Apr 18th, 2003, 11:46 AM
#6
Thread Starter
PowerPoster
I see, so i'd still have access to every method, it just makes it shorter to type? Thanks.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 18th, 2003, 05:13 PM
#7
Inheritance can look very similar, but the distinction is important.
If you have a class Fish, it will have certain properties and methods, like swim, jump, etc. If you make a class Bass, that inherits class Fish, it has the same methods (unless you override them such that a Bass swims in a peculiarly Bassy fashion).
Thus when you make an instance of class Bass, you can call its methods, and the public properties of both it and the base class Fish. If all of the base members are public, that would behave fairly similar to Imports. However, the thing about inheritance is that it allows you to include the functionality of the base class in an object without removing the security that the encapsulation within a class provides.
I think this is a lousy exlanation, I hope there's something worthwhile in it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|