Inheritance/implementing

gmc8757

Member
Joined
Dec 17, 2005
Messages
15
Programming Experience
Beginner
If you have a class that needs to inherit from another class, and implement a different class, how would the first like look like(obviously not Public Class Form1)

This is how you implement, but how do you inherit and implement? I tried lookin it up but couldn't figure it out.
Public Class TV
Implements ITVSets

Thanks
 
You cant implement another class,you can inherit a class so long as it is has not been declared 'Not Inheritable'
You cannot inherit a class ands then implement another. The implements keyword is reserved for interfaces. So you can inherit from a class and then implementent an interface within that class to achieve polymorphism. or in a less than exact sense - 'Multiple Inheritance' The code to inherit a class and implement an interface will look like this....

VB.NET:
Public Class Test
Inherits BaseTest
Implements ITestInterface
 
The interface you implement don't need to be a part of or related to a class you inherit from. You can implement an interface regardless of inheritance. If you inherit another class that already implemented an interface, you will will implicitly inherit that too.
 
You can't have Public can you? It says it extends the BaseTest.

Public Class Test
Inherits BaseTest
Implements ITestInterface

Would it just be?
Class Test
Inherits BaseTest
Implements ITestInterface
 
Last edited:
You can have Public OR Friend OR no modifier at all. Worth Noting though is that you can inherit from a public class and then declare it as a friend class to only be seen from inside your app.
 
Do you understand the difference between inheriting a class and implementing an interface?

When you inherit a class the derived class basically IS the same thing as the base class with some extra functionality, e.g. if Class1 has functionality A, B and C then if Class2 inherits Class1 it also has functionality A, B and C. That functionality can be modified or added to but by defualt it is the same.


An interface describes a set of functionality that all implementors will provide. It provides no implementation itself, unlike a base class. It is completely up to the implementor how the functionality is provided. Implementing the interface simpy guarantees that it will be provided. This allows different classes that may be very diffreent in many ways to be treated in exactly the same way for the specific subset of their functionality defined by the interface.

Inheriting a class and implementing an interface are independent operations, except that if you inherit a class that implements an interface you cannot explicitly implement that same interface yourself.
 
I had an idea of the difference...but that really clarified any questions I had. I really appreciate your help guys. Thanks again. Hope you don't mind too much answering my newb questions.
 
Back
Top