Object-Oriented Concepts
Object-Oriented Concepts
CONCEPTS
28-11-2014
11/17/202 ANKIT VERMA 101
0
Object Oriented Concepts
Overriding
Structure
Class
11/17/202
0
Class
11/17/202
0
Overloading & Overriding
Overloading
Provide different versions of a method that has same name &
different parameters.
Parameters can be different from name, data type or ordering of
parameters.
Overriding
Replace inherited property or method.
11/17/202
0
Class Object Example
Example:
11/17/202
0
Constructor
11/17/202
0
Constructor Types
Instance Constructors
Initialize
variable that are declared with Dim, Public, Private,
Friend, Protected etc.
You can also access Shared variable within this.
11/17/202
0
Constructor Example
11/17/202
0
Destructor
Dispose
11/17/202
0
Destructor
Dispose Method
Problem with Finalize Method is non deterministic nature.
We can’t determine Finalize Method call explicitly.
Example:
Protected Overrides Sub Finalize ( )
MsgBox (“Object Out Of Scope”)
EndSub
11/17/202
0
Structure
11/17/202
0
Structure Example
Example:
11/17/202
0
Structure With Constructor Example
Example:
11/17/202
0
Class VS Structure
Similarities:
Both are User Defined Data Types.
11/17/202
0
Class vs Structure
Differences:
Class can be Inherited from other Class, but Structure not.
11/17/202
0
Method Overloaing
28-11-2014
11/17/202 ANKIT VERMA 117
0
Method Overloading
11/17/202 118
0
Method Overloading : Example
11/17/202 119
0
Shared Members
28-11-2014
11/17/202 ANKIT VERMA 120
0
Shared Members
11/17/202 121
0
Shared Members : Example
Example:
11/17/202 122
0
Inheritance
28-11-2014
11/17/202 ANKIT VERMA 123
0
Inheritance
11/17/202 124
0
Inheritance : Keywords
Inherits
Inherits keyword is used to inherit Class.
MustInherit
Indicate that Class must be inherited by other Class.
It act as Base Class and similar to Abstract Class of Java.
NonInheritable
If class is marked NonInheritable, we can’t create its Sub Class
MyBase
Call parent Class Constructor and Parent Class Overridden Methods.
It always refers the immediate Super Class.
We can’t navigate to more than one level from the Child Class.
MyBase.MethodName is not allowed in .NET
11/17/202 125
0
Inheritance : Keywords
Overloads
Indicate that methods are Overloading.
If Methods are in same class, no necessary to write this keyword.
Overridable
Allow method to be Overridden.
Overrides keyword is used to override the Overridable Method.
NotOverridable
Prevent the method being Overridden.
MustOverride
Methods must be declared in MultiInherit Class.
MustInherit
Enable Abstract Class creation. Child Class must implement all Abstract
Methods, otherwise Child Class also must declared as Abstract Class.
11/17/202 126
0
Inheritance : Example
Example:
11/17/202 127
0
Inheritance : Example
11/17/202 128
0
Inheritance : Example
11/17/202 129
0
Method Overriding
28-11-2014
11/17/202 ANKIT VERMA 130
0
Method Overriding
Sub Class is not only Inheriting but it can also give its
own implementation (override) for methods.
All the methods can’t be Overridden.
To allow methods to Overridden, Parent Class method
must use Overridable keyword.
11/17/202 131
0
Method Overriding : Example
11/17/202 132
0
Abstract
Base Class
28-11-2014
11/17/202 ANKIT VERMA 133
0
Abstract Base Class
11/17/202 135
0
Abstract Base Class : Example
Example:
11/17/202 136
0
Interface
28-11-2014
11/17/202 ANKIT VERMA 137
0
Interface
11/17/202 139
0
Interface : Example
Example:
11/17/202 140
0