CLASS AND OBJECTS
 CLASS:
A class is a user-defined data type which
has data members and member function.
A class is a collection of objects that are
similar data type.
A class definition starts with the keyword
Class followed by the class name and the
class body, ended by the End Class statement.
 A class is a construct that defines a collection of
properties and methods in a single unit.
Does not change during the execution of a
program.
CAR - class
object object
Toyota
Properties
methods
Properties
methods
Properties
methods
 Syntax:
[ <attributelist> ] [ accessmodifier ]
[ Shadows ] [ MustInherit | NotInheritable ]
[ Partial ]
Class name [ ( Of typelist ) ]
[ Inherits classname ]
[ Implements interfacenames ]
[ statements ]
End Class
 Where,
 attributelist is a list of attributes that apply to the class. Optional.
 accessmodifier defines the access levels of the class, it has values as -
Public, Protected, Friend, Protected Friend and Private. Optional.
 Shadows indicate that the variable re-declares and hides an identically
named element, or set of overloaded elements, in a base class. Optional.
 MustInherit specifies that the class can be used only as a base class and
that you cannot create an object directly from it, i.e., an abstract class.
Optional.
 NotInheritable specifies that the class cannot be used as a base class.
 Partial indicates a partial definition of the class.
 Inherits specifies the base class it is inheriting from.
 Implements specifies the interfaces the class is inheriting from.
Ex:
public class dataclass()
…….
……
End class
Creates a new class named “dataclass” can
create an object of this class data the keyword
“New” to create a new instance of a class.
Dim data As New dataclass()
or
Dim data As Dataclass=New dataclass()
 OBJECTS:
Objects are instances of a class.
An object is a combination of code and data
that can be treated as a unit.
Use objects provided by vb such as controls
forms, and data access objects.
Each object in visual basic is defined by a
class.
A class describes the variables, properties,
procedures and events of an object.
CONSTRUCTORS AND DESTRUCTORS
 A class constructor is a special member Sub of a
class that is executed whenever we create new
objects of that class.
 A constructor has the name New and it does not
have any return type.
 It is automatically called when an object is
created.
CONSTRUCTOR :
 One of the most important concepts in object-
oriented programming is that of inheritance.
Inheritance allows us to define a class in terms of
another class, which makes it easier to create
and maintain an application. This also provides
an opportunity to reuse the code functionality a
SYNTAX:
 Public Class User
 Public Sub New()
 End Sub
 End Class
 Default Constructor
 if we create a constructor without having any
parameters, we will call it as default
constructor and the instance of the class will be
initialized without any parameter values.
 Module Module1
Class User
Public name, location As String
' Default Constructor
Public Sub New()
name = "Suresh Dasari"
location = "Hyderabad"
End Sub
End Class
Sub Main()
Dim user As User = New User()
Console.WriteLine(user.name)
Console.WriteLine(user.location)
Console.WriteLine("Press Enter Key to Exit..")
Console.ReadLine()
End Sub
End Module
 Parameterized Constructor
 if we create a constructor with at least one
parameter, we will call it a parameterized
constructor and every time the instance of the
class must be initialized with parameter values
 Module Module1
Class User
Public name, location As String
' Parameterized Constructor
Public Sub New(ByVal a As String, ByVal b As String)
name = a
location = b
End Sub
End Class
Sub Main()
Dim user As User = New User("Suresh Dasari", "Hyderabad")
Console.WriteLine(user.name)
Console.WriteLine(user.location)
Console.WriteLine("Press Enter Key to Exit..")
Console.ReadLine()
End Sub
End Module
DESTRUCTORS:
 A destructor is a special member Sub of a class
that is executed whenever an object of its class
goes out of scope.
 A destructor has the name Finalize and it can
neither return a value nor can it take any
parameters. Destructor can be very useful for
releasing resources before coming out of the
program like closing files, releasing memories,
etc.
Inheritance
 One of the most important concepts in object-
oriented programming is that of inheritance.
Inheritance allows us to define a class in terms of
another class, which makes it easier to create
and maintain an application. This also provides
an opportunity to reuse the code functionality
and fast implementation time.

basic concepts of object oriented programming

  • 1.
  • 2.
     CLASS: A classis a user-defined data type which has data members and member function. A class is a collection of objects that are similar data type. A class definition starts with the keyword Class followed by the class name and the class body, ended by the End Class statement.
  • 3.
     A classis a construct that defines a collection of properties and methods in a single unit. Does not change during the execution of a program. CAR - class object object Toyota Properties methods Properties methods Properties methods
  • 4.
     Syntax: [ <attributelist>] [ accessmodifier ] [ Shadows ] [ MustInherit | NotInheritable ] [ Partial ] Class name [ ( Of typelist ) ] [ Inherits classname ] [ Implements interfacenames ] [ statements ] End Class
  • 5.
     Where,  attributelistis a list of attributes that apply to the class. Optional.  accessmodifier defines the access levels of the class, it has values as - Public, Protected, Friend, Protected Friend and Private. Optional.  Shadows indicate that the variable re-declares and hides an identically named element, or set of overloaded elements, in a base class. Optional.  MustInherit specifies that the class can be used only as a base class and that you cannot create an object directly from it, i.e., an abstract class. Optional.  NotInheritable specifies that the class cannot be used as a base class.  Partial indicates a partial definition of the class.  Inherits specifies the base class it is inheriting from.  Implements specifies the interfaces the class is inheriting from.
  • 6.
    Ex: public class dataclass() ……. …… Endclass Creates a new class named “dataclass” can create an object of this class data the keyword “New” to create a new instance of a class. Dim data As New dataclass() or Dim data As Dataclass=New dataclass()
  • 7.
     OBJECTS: Objects areinstances of a class. An object is a combination of code and data that can be treated as a unit. Use objects provided by vb such as controls forms, and data access objects. Each object in visual basic is defined by a class. A class describes the variables, properties, procedures and events of an object.
  • 8.
    CONSTRUCTORS AND DESTRUCTORS A class constructor is a special member Sub of a class that is executed whenever we create new objects of that class.  A constructor has the name New and it does not have any return type.  It is automatically called when an object is created.
  • 9.
    CONSTRUCTOR :  Oneof the most important concepts in object- oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality a
  • 10.
    SYNTAX:  Public ClassUser  Public Sub New()  End Sub  End Class
  • 11.
     Default Constructor if we create a constructor without having any parameters, we will call it as default constructor and the instance of the class will be initialized without any parameter values.
  • 12.
     Module Module1 ClassUser Public name, location As String ' Default Constructor Public Sub New() name = "Suresh Dasari" location = "Hyderabad" End Sub End Class Sub Main() Dim user As User = New User() Console.WriteLine(user.name) Console.WriteLine(user.location) Console.WriteLine("Press Enter Key to Exit..") Console.ReadLine() End Sub End Module
  • 13.
     Parameterized Constructor if we create a constructor with at least one parameter, we will call it a parameterized constructor and every time the instance of the class must be initialized with parameter values
  • 14.
     Module Module1 ClassUser Public name, location As String ' Parameterized Constructor Public Sub New(ByVal a As String, ByVal b As String) name = a location = b End Sub End Class Sub Main() Dim user As User = New User("Suresh Dasari", "Hyderabad") Console.WriteLine(user.name) Console.WriteLine(user.location) Console.WriteLine("Press Enter Key to Exit..") Console.ReadLine() End Sub End Module
  • 15.
    DESTRUCTORS:  A destructoris a special member Sub of a class that is executed whenever an object of its class goes out of scope.  A destructor has the name Finalize and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories, etc.
  • 16.
    Inheritance  One ofthe most important concepts in object- oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.