SlideShare a Scribd company logo
3
Most read
12
Most read
14
Most read
Constructor and Destructor
BY LECTURER Suraj Pandey CCT college
Creating constructor and Destructor
BY LECTURER Suraj Pandey CCT
college
 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.
 If a class have a constructor, then the object of that class
will be initialized automatically.
 To create a constructor for a class, create a procedure
named Sub New anywhere in the class definition. To
create a parameterized constructor, specify the names
and data types of arguments to Sub New just as you
would specify arguments for any other procedure.
 Following program explains the concept of constructor:
BY LECTURER Suraj Pandey CCT
college
BY LECTURER Suraj Pandey CCT
college
 When the above code is compiled and executed, it
produces the following result:
Object is being created
Length of line : 6
BY LECTURER Suraj Pandey CCT
college
Parameterized Constructor
BY LECTURER Suraj Pandey CCT
college
 A default constructor does not have any parameter but if
you need a constructor can have parameters. Such
constructors are called parameterized constructors.
This technique helps you to assign initial value to an
object at the time of its creation as shown in the
following example:
The default constructor
 Public Sub New()
Console.Writeline ("Dog is Created With Age Zero")
Age=0
End Sub
BY LECTURER Suraj Pandey CCT
college
The parameterized constructor
 Public Sub New(val as Integer)
Console.Writeline ("Dog is Created With Age " +
Convert.ToString(val))
Age=val
End Sub
BY LECTURER Suraj Pandey CCT
college
BY LECTURER Suraj Pandey CCT
college
BY LECTURER Suraj Pandey CCT
college
 When the above code is compiled and executed, it
produces the following result:
Object is being created, length = 10
Length of line set by constructor : 10
Length of line set by setLength : 6
BY LECTURER Suraj Pandey CCT college
Destructor
 A Destructor is a special function which is called
automatically when a class is destroyed. In VB.NET, you
should use Finalize() routine to create 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.
 Destructors cannot be inherited or overloaded.
BY LECTURER Suraj Pandey CCT
college
BY LECTURER Suraj Pandey CCT
college
 Following example explains the concept of destructor:
BY LECTURER Suraj Pandey CCT
college
BY LECTURER Suraj Pandey CCT
college
 When the above code is compiled and executed, it
produces the following result:
Object is being created
Length of line : 6
Object is being deleted
Use of Constructor and Destructor
Constructors: Special methods which has following important points.
In VB.NET, this is defined as a Sub with the name of New.
No return type.
It's called whenever an object is created using the New statement.
Can be overloaded.
Can be private.
Destructors: Special methods Which has The following important points.
This is called Finalize in VB.NET.
VB.NET compiler creates a default Finalize method.
Can never be private.
By default is public.
Called automatically when an object releases it memory.
BY LECTURER Suraj Pandey CCT college
BY LECTURER Suraj Pandey CCT college

More Related Content

What's hot (20)

PPTX
Visual Basic Controls ppt
Ranjuma Shubhangi
 
PPTX
Integrity Constraints
madhav bansal
 
PPTX
Oops in vb
Dalwin INDIA
 
PPTX
System software - macro expansion,nested macro calls
SARASWATHI S
 
PPTX
MACRO PROCESSOR
Bhavik Vashi
 
PPTX
sutherland- Hodgeman Polygon clipping
Arvind Kumar
 
PPTX
JAVA AWT
shanmuga rajan
 
PPTX
Java swing
Apurbo Datta
 
PPTX
Ado.Net Tutorial
prabhu rajendran
 
PPTX
Windows form application_in_vb(vb.net --3 year)
Ankit Gupta
 
PPTX
Video display devices
shalinikarunakaran1
 
PPTX
joins in database
Sultan Arshad
 
PPTX
Decomposition methods in DBMS
soniyagoyal3
 
PPSX
Functional dependency
Dashani Rajapaksha
 
PPTX
Single pass assembler
Bansari Shah
 
PPTX
Two pass Assembler
Satyamevjayte Haxor
 
PPTX
Dialog box in vb6
Saroj Patel
 
PPTX
Linked list
akshat360
 
PPTX
object oriented methodologies
Amith Tiwari
 
PPTX
MySQL Data types
Kaveen Prathibha Kumarasinghe
 
Visual Basic Controls ppt
Ranjuma Shubhangi
 
Integrity Constraints
madhav bansal
 
Oops in vb
Dalwin INDIA
 
System software - macro expansion,nested macro calls
SARASWATHI S
 
MACRO PROCESSOR
Bhavik Vashi
 
sutherland- Hodgeman Polygon clipping
Arvind Kumar
 
JAVA AWT
shanmuga rajan
 
Java swing
Apurbo Datta
 
Ado.Net Tutorial
prabhu rajendran
 
Windows form application_in_vb(vb.net --3 year)
Ankit Gupta
 
Video display devices
shalinikarunakaran1
 
joins in database
Sultan Arshad
 
Decomposition methods in DBMS
soniyagoyal3
 
Functional dependency
Dashani Rajapaksha
 
Single pass assembler
Bansari Shah
 
Two pass Assembler
Satyamevjayte Haxor
 
Dialog box in vb6
Saroj Patel
 
Linked list
akshat360
 
object oriented methodologies
Amith Tiwari
 

Similar to vb.net Constructor and destructor (20)

PPTX
Constructor& destructor
chauhankapil
 
PPTX
Constructors in C++.pptx
Rassjb
 
PPTX
Constructor destructor.ppt
Karthik Sekar
 
PPTX
Constructor and Destructor
Sunipa Bera
 
PPTX
An introduction to Constructors and destructors in c++ .pptx
olisahchristopher
 
PPTX
Constructor & destructor
Saharsh Anand
 
PPTX
Constructors & Destructors
Rokonuzzaman Rony
 
PPTX
Constructor and destructor in oop
Samad Qazi
 
PPTX
Constructor and destructor
rajshreemuthiah
 
PPT
5 Constructors and Destructors
Praveen M Jigajinni
 
PPT
C++ classes tutorials
akreyi
 
PPTX
constructor & destructor in cpp
gourav kottawar
 
PPTX
constructor & destructor in cpp
gourav kottawar
 
PDF
Constructors and destructors
Prof. Dr. K. Adisesha
 
PPT
ConsTRUCTION AND DESTRUCTION
Shweta Shah
 
PDF
Unit 2 Methods and Polymorphism-Object oriented programming
DhananjaySateesh
 
PPTX
basic concepts of object oriented programming
infotechsaasc
 
PPTX
C++ Unit-III Lecture-3a-C++ Programming Concepts
dharawagh9999
 
PDF
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
PPT
Constructor & Destructor
KV(AFS) Utarlai, Barmer (Rajasthan)
 
Constructor& destructor
chauhankapil
 
Constructors in C++.pptx
Rassjb
 
Constructor destructor.ppt
Karthik Sekar
 
Constructor and Destructor
Sunipa Bera
 
An introduction to Constructors and destructors in c++ .pptx
olisahchristopher
 
Constructor & destructor
Saharsh Anand
 
Constructors & Destructors
Rokonuzzaman Rony
 
Constructor and destructor in oop
Samad Qazi
 
Constructor and destructor
rajshreemuthiah
 
5 Constructors and Destructors
Praveen M Jigajinni
 
C++ classes tutorials
akreyi
 
constructor & destructor in cpp
gourav kottawar
 
constructor & destructor in cpp
gourav kottawar
 
Constructors and destructors
Prof. Dr. K. Adisesha
 
ConsTRUCTION AND DESTRUCTION
Shweta Shah
 
Unit 2 Methods and Polymorphism-Object oriented programming
DhananjaySateesh
 
basic concepts of object oriented programming
infotechsaasc
 
C++ Unit-III Lecture-3a-C++ Programming Concepts
dharawagh9999
 
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
Constructor & Destructor
KV(AFS) Utarlai, Barmer (Rajasthan)
 
Ad

More from suraj pandey (20)

PPT
Systemcare in computer
suraj pandey
 
PPTX
Overloading and overriding in vb.net
suraj pandey
 
PPT
Basic in Computernetwork
suraj pandey
 
PPT
Computer hardware
suraj pandey
 
PPT
Dos commands new
suraj pandey
 
PPT
History of computer
suraj pandey
 
PPT
Dos commands
suraj pandey
 
PPT
Basic of Internet&email
suraj pandey
 
PPT
Basic fundamental Computer input/output Accessories
suraj pandey
 
PPT
Introduction of exception in vb.net
suraj pandey
 
PPT
Transmission mediums in computer networks
suraj pandey
 
PPTX
Introduction to vb.net
suraj pandey
 
PPT
Introduction to computer
suraj pandey
 
PPT
Computer Fundamental Network topologies
suraj pandey
 
PPTX
Basic of Computer software
suraj pandey
 
PPT
Basic using of Swing in Java
suraj pandey
 
PPT
Basic Networking in Java
suraj pandey
 
PPT
Basic Java Database Connectivity(JDBC)
suraj pandey
 
PPT
Graphical User Interface in JAVA
suraj pandey
 
PPT
Generics in java
suraj pandey
 
Systemcare in computer
suraj pandey
 
Overloading and overriding in vb.net
suraj pandey
 
Basic in Computernetwork
suraj pandey
 
Computer hardware
suraj pandey
 
Dos commands new
suraj pandey
 
History of computer
suraj pandey
 
Dos commands
suraj pandey
 
Basic of Internet&email
suraj pandey
 
Basic fundamental Computer input/output Accessories
suraj pandey
 
Introduction of exception in vb.net
suraj pandey
 
Transmission mediums in computer networks
suraj pandey
 
Introduction to vb.net
suraj pandey
 
Introduction to computer
suraj pandey
 
Computer Fundamental Network topologies
suraj pandey
 
Basic of Computer software
suraj pandey
 
Basic using of Swing in Java
suraj pandey
 
Basic Networking in Java
suraj pandey
 
Basic Java Database Connectivity(JDBC)
suraj pandey
 
Graphical User Interface in JAVA
suraj pandey
 
Generics in java
suraj pandey
 
Ad

Recently uploaded (20)

PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Dimensions of Societal Planning in Commonism
StefanMz
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 

vb.net Constructor and destructor

  • 1. Constructor and Destructor BY LECTURER Suraj Pandey CCT college
  • 2. Creating constructor and Destructor BY LECTURER Suraj Pandey CCT college  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.  If a class have a constructor, then the object of that class will be initialized automatically.  To create a constructor for a class, create a procedure named Sub New anywhere in the class definition. To create a parameterized constructor, specify the names and data types of arguments to Sub New just as you would specify arguments for any other procedure.  Following program explains the concept of constructor:
  • 3. BY LECTURER Suraj Pandey CCT college
  • 4. BY LECTURER Suraj Pandey CCT college  When the above code is compiled and executed, it produces the following result: Object is being created Length of line : 6
  • 5. BY LECTURER Suraj Pandey CCT college
  • 6. Parameterized Constructor BY LECTURER Suraj Pandey CCT college  A default constructor does not have any parameter but if you need a constructor can have parameters. Such constructors are called parameterized constructors. This technique helps you to assign initial value to an object at the time of its creation as shown in the following example:
  • 7. The default constructor  Public Sub New() Console.Writeline ("Dog is Created With Age Zero") Age=0 End Sub BY LECTURER Suraj Pandey CCT college
  • 8. The parameterized constructor  Public Sub New(val as Integer) Console.Writeline ("Dog is Created With Age " + Convert.ToString(val)) Age=val End Sub BY LECTURER Suraj Pandey CCT college
  • 9. BY LECTURER Suraj Pandey CCT college
  • 10. BY LECTURER Suraj Pandey CCT college  When the above code is compiled and executed, it produces the following result: Object is being created, length = 10 Length of line set by constructor : 10 Length of line set by setLength : 6
  • 11. BY LECTURER Suraj Pandey CCT college
  • 12. Destructor  A Destructor is a special function which is called automatically when a class is destroyed. In VB.NET, you should use Finalize() routine to create 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.  Destructors cannot be inherited or overloaded. BY LECTURER Suraj Pandey CCT college
  • 13. BY LECTURER Suraj Pandey CCT college  Following example explains the concept of destructor:
  • 14. BY LECTURER Suraj Pandey CCT college
  • 15. BY LECTURER Suraj Pandey CCT college  When the above code is compiled and executed, it produces the following result: Object is being created Length of line : 6 Object is being deleted
  • 16. Use of Constructor and Destructor Constructors: Special methods which has following important points. In VB.NET, this is defined as a Sub with the name of New. No return type. It's called whenever an object is created using the New statement. Can be overloaded. Can be private. Destructors: Special methods Which has The following important points. This is called Finalize in VB.NET. VB.NET compiler creates a default Finalize method. Can never be private. By default is public. Called automatically when an object releases it memory. BY LECTURER Suraj Pandey CCT college
  • 17. BY LECTURER Suraj Pandey CCT college