Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Classes in VB.NET

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-04-2009
Member
 
Join Date: Oct 2008
Posts: 54
Classes in VB.NET
  

Classes in VB.NET
Classes are types and Objects are instances of the Class. Classes and Objects are very much related to each other. Without objects you can't use a class.

Code:
Public Class Test

----- Variables
-----Methods
-----Properties
-----Events

End Class

Code:
Imports System.Console

Sub Main()
Dim obj As New Test()
'creating a object obj for Test class
obj.disp()
'calling the disp method using obj
Read()
End Sub

End Module

Public Class Test
'creating a class named Test
Sub disp()
'a method named disp in the class
Write("Welcome to OOP")
End Sub
End Class

Reply With Quote
  #2  
Old 10-04-2009
Member
 
Join Date: May 2008
Posts: 29
Re: Classes in VB.NET

Simple Inheritance

Code:
Public Class Tester
    Public Shared Sub Main
        Dim objJohn As New John
        objJohn.Walk()
    End Sub
End Class


Public Class Person
    Public Sub Walk()
        Console.WriteLine("Walking...")
    End Sub
End Class

Class John
    Inherits Person
End Class
Reply With Quote
  #3  
Old 10-04-2009
Member
 
Join Date: May 2008
Posts: 24
Re: Classes in VB.NET

Call base method

Code:
Option Strict On

Public Class BaseClass
   Public Sub MainMethod()
      Console.WriteLine("Calling Me.Method1...")
      Me.Method1()
      Console.WriteLine("Calling MyClass.Method1...")
      MyClass.Method1()
   End Sub

   Public Overridable Sub Method1()
      Console.WriteLine("BaseClass.Method1...")
   End Sub
End Class

Public Class DerivedClass : Inherits BaseClass
      Public Overrides Sub Method1()
         Console.WriteLine("DerivedClass.Method1...")
      End Sub
End Class

Public Module modMain
   Public Sub Main()
      Console.WriteLine("Invoking BaseClass.MainMethod")
      Dim bc As New BaseClass
      bc.MainMethod()
      Console.WriteLine()
      Console.WriteLine("Invoking DerivedClass.MainMethod")
      Dim dc As New DerivedClass
      dc.MainMethod()
   End Sub
End Module
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Classes in VB.NET"
Thread Thread Starter Forum Replies Last Post
Problem with Inner classes Captain Carrot Software Development 5 11-03-2010 01:14 PM
What are an Autoloading Classes in PHP? Flaco Software Development 5 06-03-2010 05:49 AM
Communication between two classes ANSEL Software Development 4 04-12-2009 05:43 PM
Comparison of two classes Chrisch Software Development 3 12-10-2009 11:33 AM
C # using classes in C + + klite Software Development 3 01-10-2009 10:15 AM


All times are GMT +5.5. The time now is 10:56 AM.