0% found this document useful (0 votes)
26 views4 pages

Unit 3 Oops in

The document outlines key concepts of Object-Oriented Programming (OOP), including objects, classes, data abstraction, encapsulation, inheritance, and polymorphism. It explains how objects interact, how classes are defined and instantiated, and the roles of constructors and destructors. Additionally, it describes inheritance for reusability and polymorphism for method overloading based on different data types.

Uploaded by

charlieprasannna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Unit 3 Oops in

The document outlines key concepts of Object-Oriented Programming (OOP), including objects, classes, data abstraction, encapsulation, inheritance, and polymorphism. It explains how objects interact, how classes are defined and instantiated, and the roles of constructors and destructors. Additionally, it describes inheritance for reusability and polymorphism for method overloading based on different data types.

Uploaded by

charlieprasannna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

]

Concepts of OOP:​

●​ Objects
●​ Classes
●​ Data Abstraction and Encapsulation
●​ Inheritance
●​ Polymorphism

Objects



Objects are the basic run-time entities in an object-oriented system. Programming
problem is analyzed in terms of objects and nature of communication between them.
When a program is executed, objects interact with each other by sending messages.
Different objects can also interact with each other without knowing the details of their
data or code.​

Classes



A class is a collection of objects of similar type. Once a class is defined, any number
of objects can be created which belong to that class.​
In Visual Basic we create a class with the Class statement and end it with End Class.
The Syntax for a Class looks as follows:

Public Class Test


Variables
Methods
Properties
Events
End Class

The above syntax created a class named Test.

To create a object for this class we use the new keyword and that looks like this:

Dim obj as new Test().

FIELDS, PROPERTIES, METHODS, AND EVENTS ARE MEMBERS OF THE CLASS. THEY CAN BE DECLARED AS
PUBLIC, PRIVATE, PROTECTED, FRIEND OR PROTECTED FRIEND

Public Class House


​ Public Rooms as Integer
End Class

Data Abstraction and Encapsulation​

Abstraction refers to the act of representing essential features without including the
background details or explanations.

●​ Classes use the concept of abstraction and are defined as a list of abstract
attributes.
●​ Storing data and functions in a single unit is encapsulation.
●​ Data cannot be accessible to the outside world and only those functions which
are stored in the class can access it.

CONTRUCTORS
A CONSTRUCTOR IS A SPECIAL FUNCTION WHICH IS CALLED AUTOMATICALLY WHEN A CLASS IS
CREATED. WHEN YOU CREATE AN OBJECT, YOU MIGHT WANT TO CUSTOMIZE THAT OBJECT WITH
DATA—FOR EXAMPLE, WHEN YOU CREATE AN OBJECT OF A CLASS NAMED EMPLOYEE, YOU MIGHT WANT
TO STORE THE EMPLOYEE'S NAME, PHONE NUMBER, ID NUMBER, AND SO ON IN THAT OBJECT.

NOW I CAN STORE THE VALUE 5 INSIDE AN OBJECT OF THE DATACLASS CLASS SIMPLY BY PASSING 5 TO
THE CONSTRUCTOR, AND I CAN RETRIEVE THAT VALUE WITH THE GETDATA METHOD:

DIM DATA AS NEW DATACLASS(5)

MSGBOX(DATA.GETDATA())

DESTRUCTORS
DESTRUCTORS ARE USED TO CLEAN UP AFTER AN OBJECT (DEALLOCATING RESOURCES, FOR EXAMPLE, OR
INFORMING OTHER OBJECTS THAT THE CURRENT OBJECT WILL NO LONGER BE AVAILABLE).

THE FINALIZE DESTRUCTOR IS THE ONE YOU NORMALLY USE;

FINALIZE IS CALLED AUTOMATICALLY BY THE SYSTEM WHEN AN OBJECT IS DESTROYED (WHICH MEANS THAT
YOU SHOULD NOT EXPLICITLY CALL FINALIZE YOURSELF).

THE .NET FRAMEWORK AUTOMATICALLY RUNS THE FINALIZE DESTRUCTOR AND DESTROYS OBJECTS WHEN THE
SYSTEM DETERMINES THAT SUCH OBJECTS ARE NO LONGER NEEDED.

Inheritance


Inheritance is the process by which objects can acquire the properties of objects of
other class.

In OOP, inheritance provides reusability, like, adding additional features to an


existing class without modifying it. This is achieved by deriving a new class from the
existing one. The new class will have combined features of both the classes.

THE PROCESS OF DERIVING A NEW CLASS FROM AN EXISTING CLASS IS CALLED INHERITANCE. THE OLD CLASS IS
CALLED THE BASE CLASS AND THE NEW CLASS IS CALLED DERIVED CLASS. THE DERIVED CLASS INHERITS SOME
OR EVERYTHING OF THE BASE CLASS.

IN VISUAL BASIC WE USE THE INHERITS KEYWORD TO INHERIT ONE CLASS FROM OTHER.

THE GENERAL FORM OF DERIVING A NEW CLASS FROM AN EXISTING CLASS LOOKS AS FOLLOWS:

Public Class One


---
---
End Class
Public Class Two
Inherits One
---
---
End Class

Polymorphism



Polymorphism means the ability to take more than one form. An operation may
exhibit different behaviors in different instances. The behavior depends on the data
types used in the operation. Polymorphism is extensively used in implementing
Inheritance.

Module Module1
​ Sub Main()
​ ​ Dim two As New One()
​ ​ WriteLine(two.add(10))
​ ​ 'calls the function with one argument
​ ​ WriteLine(two.add(10, 20))
​ ​ 'calls the function with two arguments
​ ​ WriteLine(two.add(10, 20, 30))
​ ​ 'calls the function with three arguments
​ ​ Read()
​ End Sub
End Module
Public Class One
​ Public i, j, k As Integer

​ Public Function add(ByVal i As Integer) As Integer


​ ​ 'function with one argument
​ ​ Return i
​ End Function

​ Public Function add(ByVal i As Integer, ByVal j As Integer) As Integer


​ ​ 'function with two arguments
​ ​ Return i + j
​ End Function

​ Public Function add(ByVal i As Integer, ByVal j As Integer, ByVal k As


Integer) As Integer
​ ​ 'function with three arguments
​ ​ Return i + j + k
​ End Function
End Class

You might also like