abstract class in VB.NET?

bungpeng

Senior Contributor
Joined
Sep 10, 2002
Messages
906
Location
Malaysia
Can I define a "Abstract" class in VB.NET?

It means I do not need to create a object to refers to this class; I can direct use the methods/functions of the class without declared any object.

I use it before in "Java"
 
You can declare static members of a class using the Shared keyword in VB.NET:

Visual Basic:
Public Class Class1
  Public Shared Sub Boo()
  End Sub
End Class

You would then be able to call Class1.Boo() without an instance of the class.
 
Static variables in vb.net remain in existence and retain their latest values after termination of the procedure in which they are declared. They are not the same as shared members of classes.
 
I not quite undertanding, then what different between 'static' variables and 'shared' variables?

How do I declare 'static' variable? with 'Static' keyword?
 
Visual Basic:
Static var As Integer
When the variables go out of scope, they retain their values (though
can't be accessed from outside of the procedure they're declared in).

The term Static comes from the fact that the variable keeps
a static location in memory, thus preserving the data.
 
You mean "Shared" and "Static" are the same, the only different is that 'Static' can't be access from outside the procedure? right?

Actually what is the purpose for Microsoft to do that? Why don't use the same? either 'Shared' or 'Static'?
 
No, Shared means that a sub inside a class can be accessed from
anywhere, without declaring an instance of the class. In VB6, a
public method in a module did what a shared method in a class
does in VB.NET; although modules still exist in .NET, you should
use Shared methods in classes.
 
In this case: I create a class 'Car' with 2 functions 'A' and 'B'. 'A' declare as "Shared", 'B' is normal public function.

If I want to access these functions (A and B), then do I need to create object for class 'Car'?

This is what I confuse now....

Sorry because disturb you again...
 
All this information is covered in great details in the help file, within the Visual Basic .NET language reference.
 
I believe he said the Language Reference. Check out the keyword "Shared", "Static" etc. and read as much as you can - there is a GREAT deal of info around the class and member modifiers (such as public, private, shared, etc.). It's well worth the effort to spend 8 hours or so writing small sample classes and seeing what each keyword does and doesn't do. A book on VB.NET would cover this as well with good samples.

-Nerseus
 
Back
Top