Results 1 to 3 of 3

Thread: Classes in VB.NET

  1. #1
    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

  2. #2
    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

  3. #3
    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

Similar Threads

  1. Problem with Inner classes
    By Captain Carrot in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 01:14 PM
  2. What are an Autoloading Classes in PHP?
    By Flaco in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 05:49 AM
  3. Communication between two classes
    By ANSEL in forum Software Development
    Replies: 4
    Last Post: 04-12-2009, 05:43 PM
  4. Comparison of two classes
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 12-10-2009, 11:33 AM
  5. C # using classes in C + +
    By klite in forum Software Development
    Replies: 3
    Last Post: 01-10-2009, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •