Dagm
Dagm
NET
W I N D OW P RO G R A M M I N G
NAME ID
• Example Code:
Class Account
Private Balance As Decimal
Public Sub Deposit(amount As Decimal)
If amount > 0 Then Balance += amount
End Sub
Public Function GetBalance() As Decimal
Return Balance
End Function
End Class
Inheritance
• Inheritance allows a class to inherit and reuse the methods and properties
of another class, establishing a parent-child relationship between classes.
This promotes code reusability and hierarchical design.
•Benefits of Inheritance:
Code Reusability: It enables the reuse of code in multiple classes, reducing redundancy and
improving maintainability.
Hierarchical Design: Inheritance supports the creation of a hierarchical structure, allowing for
specialization and extension of functionality through a chain of parent and child classes.
Inheritance Example
Example Code:
Class Vehicle
Public Sub Move()
Console.WriteLine("Vehicle is moving")
End Sub
End Class
•Types of Polymorphism:
Compile-time: Involves method overloading, where multiple methods with the
same name exist in the same class but with different parameters.
Runtime: Involves method overriding, where a method in a subclass redefines
the behavior of a method inherited from a parent class.
Polymorphism Example
• Example Code:
Class Shape
Public Overridable Sub Draw()
Console.WriteLine("Drawing Shape")
End Sub
End Class
Interfaces define a contract that implementing classes must adhere to. They
establish a set of rules and force classes to implement the required methods.
• Example Code:
Interface IAnimal
Sub Speak()
End Interface
Constructors are special methods that initialize an object when it is created. They set
up the initial state of an object by assigning values to its attributes.
•Types of Constructors:
Default Constructor: Initializes an object with default values.
Parameterized Constructor: Accepts parameters to initialize an object with
specific values.
Shared Constructor: Used in shared classes to initialize objects shared across
instances.
Destructors in VB.NET
• Key Terms:
Events: Actions or occurrences.
Delegates: Pointers to methods.
Event Handling Example
• Example Code:
Public Class Button
Public Event Click()
• Method Overloading allows multiple methods with the same name but
different signatures.
• Example:
Class MathOps
Public Function Add(a As Integer, b As Integer) As Integer
Return a + b
End Function