0% found this document useful (0 votes)
2 views32 pages

Object Oriented Programming (Notes)

The document provides an overview of Object-Oriented Programming (OOP), detailing its necessity, principles, and characteristics, including encapsulation, inheritance, and polymorphism. It also covers Visual Studio IDE features, debugging techniques, and the phases of Object-Oriented Software Engineering (OOSE). Key concepts such as classes, objects, access specifiers, and design principles are explained, along with the importance of modularity and reusability in software development.

Uploaded by

maazbintariq46
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)
2 views32 pages

Object Oriented Programming (Notes)

The document provides an overview of Object-Oriented Programming (OOP), detailing its necessity, principles, and characteristics, including encapsulation, inheritance, and polymorphism. It also covers Visual Studio IDE features, debugging techniques, and the phases of Object-Oriented Software Engineering (OOSE). Key concepts such as classes, objects, access specifiers, and design principles are explained, along with the importance of modularity and reusability in software development.

Uploaded by

maazbintariq46
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/ 32

1

Object Oriented Programming (OOP)


Lecture # 01

Q1: - Why Do We Need Object Oriented Programming (OOP)?


Ans: Object-oriented programming languages make it easier to understand how a program
works by bringing together data and its behaviour (or method) in a single bundle called an
“object.” OOP helps in creating modular, reusable, and maintainable code by representing
real-world entities as objects with attributes (data) and methods (functions).
Q2: - Define the Object-Oriented Programming (OOP)?
Ans: Object-Oriented Programming (OOP) is a programming paradigm that organizes
software design around objects, each of which represents an instance of a class, and defines
the properties (attributes) and behaviours (methods) that objects of the class share. OOP
Languages include Object Pascal, Perl, PHP, Python, C, C++ etc.

Q3: - Define the Procedural Languages?


Ans: Procedural programming languages are a type of programming language that follows
a procedural paradigm, where a program is structured around procedures or routines (also
known as functions or subroutines). Examples include C, COBOL, Fortran, LISP, Perl, HTML,
and VBScript.

Q4: - Characteristics/Features of OOP?


Ans:

• Object: The instances of a class which are used in real functionality – its variables
and operations
• Methods: Methods define the behavior of objects, allowing them to perform specific
actions or operations.
• Attribute: Attributes represent the properties or characteristics of objects, defining
their state.
• Events: Events can be user interactions, such as clicking a button, typing on a
keyboard, or moving a mouse.
• Message: Messages are used for communication and interaction between different
components, modules, or systems within a software application or across a network.
• Receivers: refers to a component, device, or entity that is responsible for receiving
and processing messages, signals, or data from a sender or transmitter.
• Recursive Design: Every object has its own memory, which stores other objects.
• Classes: Classes are blueprints or templates for creating objects. They define the
structure and behaviour of objects by encapsulating data and methods.

SB CREATIVE
2

Q5: - Principes for creating a Cass?


Ans:

• Single Responsibility Principle (SRP)- A class should have only one reason to change
• Open Closed Responsibility (OCP)- It should be able to extend any classes without
modifying it
• Liskov Substitution Responsibility (LSR)- Derived classes must be substitutable for their
base classes
• Dependency Inversion Principle (DIP)- Depend on abstraction and not on concretion
• Interface Segregation Principle (ISP)- Prepare fine grained interfaces that are client
specific.

Lecture # 02

Q1: - Define the visual programming language (VPL)?


Ans: A visual programming language is a type of programming language that allows users
to create programs by manipulating graphical elements rather than writing code textually.
Instead of typing code using text-based syntax, users work with visual elements such as
icons, symbols, and diagrams to represent program logic and structure.

Q2: - Visual studio IDE?


Ans: Visual Studio IDE is a powerful and feature-rich development environment that
provides developers with everything they need to build high-quality software applications
efficiently.

Q3: - What is Toolbox in Visual Studio?


Ans: In Visual Studio, the Toolbox is a window that provides access to a collection of
controls, components, and tools that developers can use to design and build user
interfaces (UI) for their applications.

SB CREATIVE
3

Q4: - What is Solution Explorer in Visual Studio?


Ans: In Visual Studio, the Solution Explorer is a window that provides a hierarchical view
of the files, folders, projects, and solutions within the current development environment.

Q5: - What are Menus in Visual Studio?


Ans: In Visual Studio, the Menus refer to the top-level menu bar that provides access to
various commands, options, and features of the IDE.

Q6: - What are Properties Windows in Visual Studio?


Ans: In Visual Studio, the Properties Window is a tool window that displays and allows
users to modify the properties of selected objects or elements within the IDE

SB CREATIVE
4

Lecture # 03

Q1: - Explain to the Access Specifiers?


Ans: Access specifiers, also known as access modifiers, are keywords used in object-
oriented programming languages to control the visibility and accessibility of class members
(fields, methods, properties, and constructors) from other classes within the same program.
In Object Oriented Programming There have three main access specifiers:

a) Public Access:
when a class member is declared as public, it means that it is visible and accessible
to all other parts of the program.
Public Class MyClass
Public publicField As Integer ' Public field

Public Sub publicMethod()


' Public method
Console.WriteLine("This is a public method.")
End Sub
End Class

b) Private Access:
when a class member is declared as private, it means that it is hidden from outside
the class.
Public Class MyClass
Private privateField As Integer ' Private field

Private Sub privateMethod()


' Private method
Console.WriteLine("This is a private method.")
End Sub
End Class

SB CREATIVE
5

c) Private Access:
When you declare a member of a class as Protected, it means that the member is
accessible within the class where it is declared and within any class derived from
that class (i.e., subclasses or child classes), but it is not accessible from outside the
class hierarchy.
Public Class MyBaseClass
Protected protectedField As Integer ' Protected field

Protected Sub protectedMethod()


' Protected method
Console.WriteLine("This is a protected method.")
End Sub
End Class

Public Class MySubclass


Inherits MyBaseClass

Public Sub MyMethod()


' Can access protectedField and protectedMethod here
protectedField = 10
protectedMethod()
End Sub
End Class

Q2: - Define Encapsulation & Data Abstraction?


Ans: Encapsulation: Encapsulation is a fundamental concept in object-oriented
programming (OOP) that refers to the bundling of data (attributes) and methods (functions)
that operate on the data into a single unit, typically referred to as a class.
Data abstraction: Data abstraction is another key concept in object-oriented programming
that involves hiding the complex implementation details of data and providing a simplified
interface for interacting with it.

SB CREATIVE
6

Q3: - Define Inheritance? Also describe types of Inheritance.


Ans: Inheritance is a fundamental concept in object-oriented programming (OOP) that
allows a class (known as a subclass or derived class) to inherit properties and behaviours
(attributes and methods) from another class (known as a superclass or base class).
Types of Inheritance:
There are various types of inheritance, based on paradigm and specific language.

a) Single Inheritance:
In single inheritance, a subclass inherits from only one superclass.

b) Multiple Inheritance:
In multiple inheritance, a subclass inherits from multiple super classes.

c) Multilevel Inheritance:
In multilevel inheritance, a subclass inherits from another subclass, creating a
hierarchical chain of classes.

d) Multilevel Inheritance:
In hierarchical inheritance, multiple subclasses inherit from a single superclass.

SB CREATIVE
7

e) Hybrid Inheritance:
Hybrid inheritance is a combination of two or more types of inheritance. It often
involves multiple and multilevel inheritance, leading to a complex class hierarchy.

Q4: - Define Virtual Base Class?


Ans: A virtual base class is a special type of base class that helps prevent ambiguity and
duplication of inherited members in the derived classes. When a class is declared as a virtual
base class, it means that only one instance of that class is shared among multiple derived
classes in the inheritance hierarchy.

Q5: - Define Abstract Class?


Ans: An abstract class is one that is not used to create objects. An abstract class is designed
only to act as a base class to be inherited by other classes. It is a design concept in program
development and provides a base upon which other classes may be built.

SB CREATIVE
8

Lecture # 4

Q1: -Define Visual Studio IDE?


Ans: Visual Studio is an integrated development environment developed by Microsoft. It is
used to develop computer programs including websites, web apps, web services and mobile
apps. Developers often need to collaborate on coding projects and debugging and they do
so through an integrated development environment (IDE).
Q2: - Describe what is Control & Properties in Visual Studio IDE.
Ans: controls are visual elements used to create the user interface of an application, they
can include buttons, text boxes, labels, drop-down lists, checkboxes, radio buttons, and
many others. while properties are the customizable attributes that define the appearance
and behaviour of these controls. For example, the properties of a button control may include
its size, location, text content, font style, background color, foreground color, and event
handlers.
Q3: - What is TextBox Control in Visual Studio IDE?
Ans: In the Visual Studio Integrated Development Environment (IDE), the TextBox control
is a graphical user interface (GUI) element used to display and enable user input of text
within a software application. It provides a rectangular area on a form or window where users
can type and edit text.

Q4: - What is Label Control in Visual Studio IDE?


Ans: Labels are commonly used in graphical
user interfaces to provide context, guidance,
or descriptive information to users, helping
them understand the purpose and functionality
of various elements within the application.

SB CREATIVE
9

Lecture***Debugger

Q1: -Difference between Debugging & Debugger?


Ans: Debugging is the process of identifying and fixing issues in software code, while a
debugger is a tool or utility used by developers to assist in the debugging process by
providing features for analysing and manipulating code during runtime. Debugging is a skill
and a process, while a debugger is a software tool used to facilitate that process.
Q2: - What are Breakpoints in Visual Studio IDE?
Ans: Breakpoints are a fundamental feature of the Visual Studio IDE's debugging
capabilities, allowing developers to gain insight into their code's execution flow, analyze
variables, and diagnose and fix issues more efficiently during the development process.
Inserting Breakpoints: Developers can insert breakpoints by clicking in the left margin of
the code editor window next to the line of code where they want the program to pause.
Alternatively, breakpoints can be insert by pressing F9 while the cursor is on the desired line
of code.
Removing Breakpoints: A breakpoint can be removed in exactly the same way. (Ctrl + Shift
+ F9) - remove all breakpoints. (F9) - Toggles between inserting and removing a breakpoint
Breakpoints will be automatically removed when you close the Visual Basic Editor.

Q3: - How to Set a Watch?


Ans: Variables are added to the watch window by either right-clicking the variable and
selecting "Add Watch" or by selecting "Add Watch" from the "Debug" menu.

Q4: - What is Call Stack?


Ans: The Call Stack window shows the order in which methods and functions are getting
called. The top line shows the current function (the SendMessage method in this app). The
second line shows that SendMessage was called from the Main method, and so on.

Q5: - What is Error Trapping?


Ans: The on-Error statement is used to trap errors in Visual Basic. Visual Basic uses the
Try, catch methods in order to eliminate the need of a GoTo statement. The On Error
command must be placed in the procedure at a position before the error could arise.

Q6: - What is the Resume Statement?


Ans: The Resume statement is used to specify where to restart the flow of execution. This
can either be a label, or Next. If Next is used, execution is continued from the statement
following the statement that caused the error.

Q7: - What is the Raising an Error?


Ans: The Raise method of the Err object may be used to rethrow the error. This is particularly
useful with class modules, as you can specify the source and a description of the problem.

description = "Unable to process the data provided"


Err.Raise Err.Number, "myObject", description

SB CREATIVE
10

Lecture***(OOSE)

Q1: -Define the OOSE?


Ans: An Object-Oriented Software Engineering is a professional who designs, develops,
and maintains software systems using object-oriented programming (OOP) principles.
Object-oriented programming is a paradigm that organizes software design around data, or
objects, rather than actions and logic.
Q2: - Describe the phase of Object-Oriented Software Engineering?
Ans: The major phases of software development using object–oriented methodology are
object-oriented analysis, object-oriented design, and object-oriented implementation.
▪ Object-Oriented Analysis:
Object-Oriented Analysis (OOA) is the process of identifying, modeling, and
specifying the requirements for a software system using object-oriented concepts and
techniques. It is a crucial initial phase in the software development life cycle,
preceding design and implementation.
The primary tasks in object-oriented analysis (OOA) are −
• Identifying objects
• Organizing the objects by creating object model diagram

• Defining the internals of the objects, or object attributes


• Defining the behaviour of the objects, i.e., object actions
• Describing how the objects interact
The common models used in OOA are use cases and object models.
▪ Object-Oriented Design:
Object-oriented design includes two main stages, namely, system design and object
design.
System Design: In this stage, the complete architecture of the desired system is designed.
The system is conceived as a set of interacting subsystems that in turn is composed of a
hierarchy of interacting objects, grouped into classes. System design is done according to
both the system analysis model and the proposed system architecture.
Object Design: In this phase, a design model is developed based on both the models
developed in the system analysis phase and the architecture designed in the system design
phase. All the classes required are identified.
▪ Object-Oriented Implementation & Testing:
The design model developed in the object design is translated into code in an
appropriate programming language or software tool. The databases are created and
the specific hardware requirements are ascertained. Once the code is in shape, it is
tested using specialized techniques to identify and remove the errors in the code.

SB CREATIVE
11

Q3: -Define the Object & Class?


Ans: Object: An object in object-oriented programming (OOP) is an instance of a class. It's
a tangible entity that encapsulates state (data) and behaviour (methods or functions) within
a software system. Objects represent real-world entities or concepts and are the building
blocks of object-oriented systems.
Class: It defines the structure, behaviour, and properties of objects of that type. A class
serves as a template from which multiple objects can be instantiated, each with its own
unique state but sharing the same behaviour defined by the class.

Q4: - Define Instance Variable?


Ans: Instance variables represent the state of individual objects and hold unique data values
for each object instance. For example, consider a "Person" class with instance variables
such as "name," "age," and "gender." Each instance of the "Person" class would have its
own set of values for these instance variables, representing the specific attributes of each
person object.

Q5: - Define Object Composition?


Ans: Object composition is a fundamental concept in object-oriented programming (OOP)
that involves constructing complex objects by combining simpler objects as components or
parts. In object composition, objects are composed of other objects to achieve the desired
functionality.

Q6: - Define Abstract Class?


Ans: A class that is declared using “abstract” keyword is known as abstract class. Abstract
classes are designed to be extended by other classes, providing a template for defining
common behavior and characteristics shared by multiple subclasses.

Q7: - Define Modularity?


Ans: Modularity is the process of decomposing a problem (program) into a set of modules
so as to reduce the overall complexity of the problem. “Modularity is the property of a system
that has been decomposed into a set of cohesive and loosely coupled modules.”

Q8: - Define Data Hiding?


Ans: Data hiding only hides class data components. Both data hiding and data
encapsulation are essential concepts of object-oriented programming.

Q9: - Define Data Abstraction?


Ans: Abstraction refers to the act of representing important and special features without
including the background details or explanation about that feature. Data abstraction
simplifies database design.

Q10: - Define Reusability?


Ans: Reusability in object-oriented programming (OOP) refers to the ability to reuse existing
code components, such as classes, modules, or objects, in different contexts or projects
without modification.

SB CREATIVE
12

Q11: - Define Extensibility?


Ans: Extensibility in object-oriented programming (OOP) refers to the ability to extend or
enhance the functionality of existing classes, modules, or software systems without
modifying their original implementation.

Q12: - Define Hierarchy?


Ans: Hierarchy refers to the arrangement of classes and objects into a structured hierarchy
or tree-like structure based on their relationships and inheritance.

Q13: - Define Generalization?


Ans: Generalization refers to the process of abstracting common characteristics and
behaviour from multiple classes and consolidating them into a more general superclass or
abstract class.

Q14: - Define Specialization?


Ans: Specialization refers to the process of refining or customizing the behaviour inherited
from a superclass by creating subclasses that extend or specialize the functionality of the
superclass.

Q15: - Define Link?


Ans: A link represents a connection through which an object collaborates with other objects.
A link depicts the relationship between two or more objects.

Q16: - Define Association?


Ans: Association depicts the relationship between objects of one or more classes. A link can
be defined as an instance of an association.

Degree of an Association: Degree of an association denotes the number of classes


involved in a connection. Degree may be unary, binary, or ternary.

• A unary relationship connects objects of the same class.


• A binary relationship connects objects of two classes.
• A ternary relationship connects objects of three or more classes.

SB CREATIVE
13

Q17: - Define Aggregation OR Composition?


Ans: Aggregation or composition is a relationship among classes by which a class can be
made up of any combination of objects of other classes. It allows objects to be placed directly
within the body of other classes.

Q18: - Describe the Benefits of using Object Model.


Ans: The benefits of using the object model are −
• It helps in faster development of software.
• It is easy to maintain. Suppose a module develops an error, then a programmer can
fix that particular module, while the other parts of the software are still up and running.
• It supports relatively hassle-free upgrades.
• It enables reuse of objects, designs, and functions.
• It reduces development risks, particularly in integration of complex systems.

SB CREATIVE
14

Lecture***(OOSE)

Q1: -Define the Event Driven Programming?


Ans: Event-driven programming is a programming paradigm where the flow of the program's
execution is determined by events, such as user actions (e.g., mouse clicks, keyboard
presses), system notifications, or messages from other parts of the program.
Q2: - What is Event Callback?
Ans: Event callback is a function that is invoked when something significant happens like
when click event is performed by user or the result of database query is available.
Q3: -Describe the Advantages of Event Driven Programming?
Ans: Event-driven programs are highly responsive because they can react to user
interactions and external stimuli immediately as events occur. This responsiveness
enhances user experience, making applications feel more interactive and engaging.
Another advantage of Event-driven programming, encourages code reuse by promoting
modular designs and encapsulating functionality within self-contained components.
Reusable components can be easily integrated into different parts of the system or shared
across multiple projects, reducing development time and effort.
Event-driven programming offers numerous advantages, including responsiveness,
modularity, scalability, and flexibility, making it a powerful paradigm for developing
interactive, scalable, and maintainable software systems.
Q4: - Describe common events of VB Controls?
Ans: Events common to most VB controls are described in the table below.

Event Occurs When


Change The user modifies text in a combo box or text box.
Click The user clicks the primary mouse button on an object.
DblClick The user double-clicks the primary mouse button on an object.
DragDrop The user drags an object to another location.
DragOver The user drags an object over another control.
GotFocus An object receives focus.
KeyDown The user presses a keyboard key while an object has focus.
KeyPress The user presses and releases a keyboard key while an object has focus.
KeyUp The user releases a keyboard key while an object has focus.
LostFocus An object loses focus.
MouseDown The user presses any mouse button while the mouse pointer is over an
object.
MouseMove The user moves the mouse pointer over an object.
MouseUp The user releases any mouse button while the mouse pointer is over an
object.

SB CREATIVE
15

Q5: - What is TabIndex Property?


Ans:
In Visual Basic (VB), the ‘TabIndex’ property, controlling the tab order of controls within a
form. It determines the sequence in which controls receive focus when users navigate
through the form using the keyboard's "Tab" key.
Q6: - What is SelStart & SelLength?
Ans: SelStart Property: SelStart represents the starting position of the text selection within
the text box. It specifies the index of the character where the selection begins. The index is
zero-based, meaning the first character has an index of 0, the second character has an index
of 1, and so on.
SelLength Property: SelLength represents the length of the selected text within the text
box. It specifies the number of characters selected from the starting position (SelStart). If
no text is selected, SelLength is zero. If text is selected, SelLength indicates the number of
characters selected.

SB CREATIVE
16

Lecture***Objects in VB

Q1: -Define the Object? Also Describe to create object from a class.
Ans: Each object in Visual Basic is defined by a class. A class describes the variables,
properties, procedures, and events of an object. An object is a combination of code and data
that can be treated as a unit. An object can be a piece of an application, like a control or a
form.
Create an object from a class:
1. Determine from which class you want to create an object.
2. Write a Dim Statement to create a variable to which you can assign a class instance.
The variable should be of the type of the desired class.
3. Dim nextCustomer As customer
4. Add the New Operator keyword to initialize the variable to a new instance of the class.
5. Dim nextCustomer As New customer
6. You can now access the members of the class through the object variable.
7. nextCustomer.accountNumber = lastAccountNumber + 1

Q2: - Define multiple Instances?


Ans: In Visual Basic (VB), you can define multiple instances of a class by creating multiple
objects from that class. For example, if you add three check boxes to a form, each check
box object is an instance of the CheckBox class. The individual CheckBox objects share a
common set of characteristics and capabilities (properties, variables, procedures, and
events) defined by the class.
Q3: -Describe the object members.
Ans: Member Access:
You access a member of an object by specifying, in order, the name of the object variable, a
period/dot(.), and the name of the member. The following example sets the Text property of
a Label object.

warningLabel.Text = "Data not saved"

Fields & Properties:


fields and properties used to represent the state of an object. They work together to
encapsulate data within an object and provide controlled access to that data from outside
the object.
Their values with assignment statements the same way you retrieve and set local variables
in a procedure. The following example retrieves the Width property and sets
the ForeColor property of a Label object.

Dim warningWidth As Integer = warningLabel.Width


warningLabel.ForeColor = System.Drawing.Color.Red

SB CREATIVE
17

Methods:
A method is an action that an object can perform. For example, Add is a method of
the ComboBox object that adds a new entry to a combo box.
The following example demonstrates the Start method of a Timer object.

Dim safetyTimer As New System.Windows.Forms.Timer


safetyTimer.Start()

Events:
Events represent occurrences or happenings within an object. They allow other parts of the
program to respond to actions or changes in the object's state. Events are declared using
the “Event” keyword. For example:
Public Event PropertyChanged As EventHandler

Instance Members:
When you create an object from a class, the result is an instance of that class. Members that
are not declared with the Shared keyword are instance members An instance member
variable can have different values in different instances.

Shared Members:
A shared member exists only once, no matter how many instances of its class you create, or
even if you create no instances. A shared member variable, for example, has only one value,
which is available to all code that can access the class. Members declared with
the Shared keyword are shared members.

Q4: - Define ActiveX? Also Describe their components.


Ans: ActiveX is a framework of Microsoft for defining reusable software components in a
programming language independent way. Software application can then be composed from
one or more of these components in order to provide their functionality.
ActiveX Components:
The components that you create using ActiveX technology are of different types. The
following are the different types of ActiveX components.
1. ActiveX Applications (ActiveX .EXE)
Each component has a collection of properties, methods and events that can be
accessed from outside. These properties, methods and events are collectively called
as interface of the component.
2. ActiveX Code Components (ActiveX .DLL)
ActiveX code components do not run as separate applications, instead they are run in
the same process area as the client (the application that is using the code component).

SB CREATIVE
18

3. ActiveX Controls (.OCX controls)


An ActiveX control may deal with displaying a calendar, another may deal with
displaying running digital clock and so on. There are hundreds of ActiveX controls
available from various vendors, whose primary job is creating ActiveX controls and sell
them to developers.
4. ActiveX Document (. VBD Document)
ActiveX documents are Internet pages. You can use ActiveX documents to create
interactive Internet application. Each ActiveX document is a Web page. An ActiveX
document can host ActiveX controls and can invoke dialog boxes and so on. Visual
Basic 6.0 has introduced DHTML application. DHTML application provides better
alternative to ActiveX document application.

Q5: -Describe the OLE Processing.


Ans: OLE (Object Linking and Embedding) processing refers to a technology developed by
Microsoft that allows objects created in one application to be embedded or linked to
documents created in another application. OLE enables compound documents where
different types of data, such as text, images, charts, and even entire documents, can be
combined and manipulated together within a single container.

• OLE Embedding:
Embedding means if one window application document contains a copy of other
window application document. This enables compound documents where different
types of data, such as text, images, charts, spreadsheets, or even entire documents,
can be combined into a single container.

• OLE Linking:
Linking means that the container application that contains a pointer to the original file.
his enables compound documents where different types of data, such as text, images,
charts, spreadsheets, or entire documents, can be dynamically linked together.

SB CREATIVE
19

Lecture***Modular Programming

Q1: -Define the Modular Programming?


Ans: Modular programming is a general programming concept where developers separate
program functions into independent pieces. These pieces then act like building blocks, with
each block containing all the necessary parts to execute one aspect of functionality.
Q2: - Describe the types of Modules?
Ans: These are the main types of modules in Visual Basic:
Form Modules: They are specific to VB form (windows or dialog boxes). Form modules
typically contain event handler procedures, such as ‘Load’, ‘click’, ‘TextChanged’, etc. Form
modules (.FRM file name extension) are the foundation of most Visual Basic applications.
Class Modules: They are Used to define custom cases in VB. Form encapsulate data and
behaviour into objects. They contain properties, methods, events, and other members. Class
modules (.CLS file name extension) are the foundation of object-oriented programming in
Visual Basic. There properties are Get (returns an object). Let (sets a value in the class), Set
(sets an object in the class).
Standard Modules: A standard code module is a Visual Basic file with extension .bas, which
is added to project. Standard code module does not contain a form, only code. Standard
code module has a general declarations section and procedure, just like form module.
Q3: - Describe the Subroutines & Functions? Also describe why we use
subroutines?
Ans: Subroutines: Subroutines are blocks of code that perform a specific task or set of
tasks. They do not return a value. Subroutines can contain statements to perform operations,
manipulate data, or execute other procedures.
Functions: Functions are similar to subroutines but differ in that they return a value. They
are define using the ‘Function’ keyword. They are called in expressions and can be assigned
to variables or used directly in calculations.
Why use Subroutines: subroutines are an essential programming construct that allows
you to define reusable blocks of code, promote code modularity and abstraction, and improve
code organization. They are widely used in programming to simplify complex tasks and
promote code reuse and maintainability.
Q4: - Define Comments?
Ans: A comment is a line that is NOT source code. it is there as guidance to the person
reading the code. Comments begin with an apostrophe (" ' ") and end with a new line.

SB CREATIVE
20

Q5: - What is Scope? Also describe why we use it?


Ans: Scope represents where in your program the subroutine can be called from.
Subroutines with a Private scope can only be called from the source file from where they
were defined. Subroutines with a Public scope can be called from anywhere in your program.
Why use Scope: scope is a fundamental concept in programming that helps organize code,
prevent conflicts, manage memory efficiently, and improve code maintainability and
readability.
Q6: - What Parameters?
Ans: Parameters, also called Arguments, are variables that can be "passed into" a
subroutine. A subroutine with parameters looks like this:

Private Sub DisplayAdd(x As Integer, y As Integer)

Q7: - Describe ByRef & ByVal parameters?


Ans: Parameters can be sent to a subroutine By Reference (ByRef) or By Value (ByVal).
ByRef parameters allow the subroutine or function to modify the original value passed from
the caller. ByRef use when you want the subroutine or function to modify the original value
of parameter. ByVal parameter is passed by value, a copy of the actual value passed from
caller is passed to the subroutine or function. Using ByVal for parameters that should not be
modified by the subroutine or function.

SB CREATIVE
21

Lecture***Variables & Constants

Q1: -Define the Variables?


Ans: variables are used to store data within objects. A variable is a word or letter used to
reference data used in a program. That data may be an integer like "23", a floating-point
number like "23.23", a string like "Hello World!", and many other data types.

The following are the requirements when naming the variables in Visual Basic:

• It must be less than 255 characters


• No spacing is allowed
• It must not begin with a number
• Period (dot) is not permitted

Q2: -How to Declaring Variables in VB?

Ans: In Visual Basic (VB), variables are declared, using name of variables (Dim, public,
private, etc.) and optionally its data type. The syntax to declare a variable in Visual Basic is
as follows:

Dim VariableName As DataType

Q2: -Describe the Scop of Variable Declaration?


Ans: The scope determines where in the program the variable can be used and accessed.
The keyword used to declare a variable and the location in which its declared defines the
scope and duration in which a variable is available.

SB CREATIVE
22

Lecture***4 Pillars of OOP

Q1: -Define Data Abstraction?

Ans: Data abstraction is the process of hiding unnecessary details of an object’s


internal structure. By abstracting an object’s data, its structure and behaviour can be
kept separate and more easily understood. Suppose you want to create a banking
application and you are asked to collect all the information about your customer. There are
chances that you will come up with the following information about the customer.

Q2: -Define Encapsulation?

Ans: Encapsulation is the process of wrapping data and related functions into a single
unit (object). Encapsulation limits access to object data and methods, preventing their
misuse and ensuring their proper functioning. Let's take an example of mobile device. With
the help of mobile devices, you can perform various functions like taking a picture, sending
a message, recording video/ audio, access the web and much more.
The features mentioned above are functionalities of most of the smartphone. However, you
don't need to understand the internal functioning details of those features before using this
program.

Q3: -Define Polymorphism?

Ans: Polymorphism, in the simplest terms, means "many forms." In the context of Object-
Oriented Programming (OOP), polymorphism allows objects of different classes to be treated
as instances of a common superclass. polymorphism enables code to be written in a way
that is more flexible and adaptable to different types of objects, promoting code reusability,
extensibility, and ease of maintenance.

For example, you have a smartphone for communication. The communication mode you
choose could be anything. It can be a call, a text message, a picture message, mail, etc. So,
the goal is common that is communication, but their approach is different. This is
called Polymorphism.

SB CREATIVE
23

Static Polymorphism: (Overloading)

Static polymorphism, also known as compile-time polymorphism, is achieved through


method overloading and operator overloading. Method overloading involves defining
multiple methods with the same name but different parameter lists within the same class.
The compiler determines which method to call based on the number and types of
arguments passed to the method at compile time.

Dynamic Polymorphism: (Overriding)

Dynamic polymorphism, also known as runtime polymorphism, is achieved through method


overriding and interface implementation. Method overriding involves redefining a method
in a subclass that is already defined in its superclass. The decision of which method to call
is made at runtime based on the actual object type, rather than the reference type.

Q4: -Define Inheritance?


Ans: Inheritance is the ability to create a new class (child class) from an existing one
(parent class). The child class typically inherits the attributes (members and methods) of
the parent class, although it can also redefine them.

Q5: -Define Parent Class (Superclass)?


Ans: The parent class, also known as the superclass, is the class that serves as the
blueprint for other classes. It defines common properties, methods, and behaviours that
are shared among multiple related classes. The parent class typically contains general
characteristics and functionalities that can be inherited by its child classes.

Q6: -Define Child Class (Subclass)?


Ans: The child class, also known as the subclass, is a class that inherits properties,
methods, and behaviours from its parent class. It extends or specializes the functionalities
of the parent class by adding new properties or methods or by overriding existing ones.
The child class can access and use all the public and protected members of its parent
class.

SB CREATIVE
24

Lecture***Built in Functions

Q1: -What is MsgBox() Function?

Ans: In Visual Basic (VB), MsgBox() is a built-in function used to display a message box
(dialog box) to the user. It is commonly used for showing informational messages, warnings,
errors, or asking for user input in VB applications. It provides various options for customizing
the appearance and behaviour of the message box based on the requirements of the
application.
returnVal = MsgBox (prompt, styleVal, title)

Q2: -What is Prompt parameter?

Ans: The prompt parameter is a string value (either a string literal or a string variable) that
supplies the message to be displayed.

Q3: -What is StyleVal?

Ans: The styleVal parameter is either an integer style value from 0 to 5, or a named constant
that can be used instead of the corresponding integer value, that determines which command
buttons will appear on the message box

Q4: -What is returnVal?

Ans: The returnVal value returned by the MsgBox() function is an integer value that
indicates which button the user has clicked in response to the message box being displayed.

Q5: -What is InputBox() Function?

Ans: The InputBox() function in Visual Basic (VB) is a built-in function that displays a dialog
box to prompt the user for input. It allows developers to obtain input from the user, such as
text or numeric values, in a convenient and user-friendly manner. The user's input can then
be captured and used in the VB application.

returnString = InputBox (prompt, title, defaultText, xpos, ypos)

SB CREATIVE
25

Q6: -Describe the String Functions?

Ans:
Function Description

Returns n characters from the text string referred to by str,


Mid (str, pos, n)
starting at character position pos.

Microsoft.VisualBasic.left Returns the n left-most characters from the text string referred
(str, n) to by str.

Microsoft.VisualBasic.right Returns the n right-most characters from the text string referred
(str, n) to by str.

Removes the white space (if any) at either end of the text string
Trim (str)
referred to by str, and returns the result.

Removes the white space (if any) at the left-hand end of the text
LTrim (str)
string referred to by str, and returns the result.

Removes the white space (if any) at the right-hand end of the
RTrim (str)
text string referred to by str, and returns the result.

Looks for an occurrence of the substring str2 within the


string str1, starting at character position n. If successful, the
InStr (n, str1, str2) function returns the character position at which the substring is
found (or zero if the substring cannot be found).

Converts the string referred to by str to all upper-case


UCase (str)
characters, and returns the result.

Converts the string referred to by str to all lower-case


LCase (str)
characters, and returns the result.

Returns the ASCII character corresponding to the 8-bit character


Chr (charCode) code charCode (note – some characters are non-printing
characters, and will not be visible on screen).

Returns the 8-bit ASCII character code corresponding


Asc (character)
to character.

SB CREATIVE
26

Q7: -Describe the Maths Functions?


Function Description

Math.Sqrt (n) Returns the square root of a number, n.

Math.Abs (n) Returns the absolute value of a number, n.

Returns the exponential value of a number, n – i.e. e n.


Math.Exp (n)
Note: e = 2.71828182

Fix (n) Returns the integer part of a floating point number, n.

Returns the integer part of a floating point number, n, for


Int (n) positive numbers, or the next smallest integer value for
negative numbers.

Math.Log (n) Returns the natural logarithm of a number, n.

Rnd () Returns a randomly generated value between 0 and 1.

Round (n,m) Rounds a number, n, up (or down) to m decimal places.

Q8: -What is Formatting the Data & Time?


Ans: The Format() function can also be used to specify how date and time values are
displayed. The function is used as follows:
Format (Date, "styleArg")
Format () Date Style Arguments

Style Argument Description

"General Date" Displays the date and time in the format: dd/mm/yyyy hh:mm:ss

"Long Date" Displays the date in the format: 06 October 2009

"Short Date" Displays the date in the format: dd/mm/yyyy

"Long Time" Displays the time in the format: h:mm:ss

"Short Time" Displays the time in the format: hh:mm

SB CREATIVE
27

Lecture***Data Control

Q1: -What is Data Control? And how they connect with Database?
Ans: Data Controls" are components or objects that allow you to interact with data from a
database within your application's user interface. These controls provide a visual
representation of data and enable users to view, manipulate, and update it without directly
interacting with the database.

To connect the data control to this database, double-click the DatabaseName property in
the Properties window and then click on the button with three dots on the right to open a
file selection dialog. From the dialog, search the folders of your hard drive to locate the
database file NWIND.MDB.

Q2: -What is Data Provider?


Ans: A data provider is used for connecting to a database, executing commands and
retrieving data, storing it in a dataset, reading the retrieved data and updating the database.
Q3: -What is DataSet?
Ans: A DataSet is an in-memory representation of a set of data retrieved from a data
source, typically a database. It is part of the ADO.NET framework and provides a
disconnected, cache-like structure that enables you to work with data in a flexible and
efficient manner.

Lecture***Data Control

Q1: -Define Operator? Also Describe the Arithmetic, Conditional & Logical
Operators.
Ans: An operator is a symbol or keyword that performs an operation on one or more
operands, producing a result. Operators are fundamental building blocks in programming
languages, enabling you to perform various computations, comparisons, and logical
operations.

Here's a breakdown of different types of operators:

1. Arithmetic Operators: Arithmetic operators are used to perform mathematical


operations on numerical operands. Common arithmetic operators include:

• Addition (+): Adds two operands.


• Subtraction (-): Subtracts the second operand from the first.
• Multiplication (*): Multiplies two operands.
• Division (/): Divides the first operand by the second.
• Modulus (%): Computes the remainder of dividing the first operand by the
second.
• Increment (++) and Decrement (--): Increase or decrease the value of an
operand by 1.
SB CREATIVE
28

2. Conditional Operators: Conditional operators are used to perform comparisons and


make decisions based on conditions. Common conditional operators include:

• Equal to (==): Checks if two operands are equal.


• Not equal to (!=): Checks if two operands are not equal.
• Greater than (>), Greater than or equal to (>=): Compares if the first operand is
greater than or equal to the second.
• Less than (<), Less than or equal to (<=): Compares if the first operand is less
than or equal to the second.

3. Logical Operators: Logical operators are used to perform logical operations on


Boolean operands. Common logical operators include:

• AND (&&): Returns true if both operands are true.


• OR (||): Returns true if at least one of the operands is true.
• NOT (!): Returns the opposite of the operand's Boolean value

Q1: -Describe If Statement.

Ans: If statement is used to conditionally execute a block of code based on the evaluation
of a Boolean expression. Here's an overview of the If statement syntax in VB:

1. Simple If Statement:
If condition Then

' Statements to execute if condition is True

End If

if the condition evaluates to True, the statements within the If block are executed. If the
condition is False, the statements are skipped.
Example:
Dim x As Integer = 5

If x = 5 Then

Console.WriteLine("x is equal to 5")

End If

SB CREATIVE
29

2. If...Else Statement:
If condition Then

' Statements to execute if condition is True

Else

' Statements to execute if condition is False

End If

if the condition is True, the statements within the first block are executed; otherwise, the
statements within the Else block are executed.
Example:
Dim x As Integer = 3

If x > 5 Then

Console.WriteLine("x is greater than 5")

Else

Console.WriteLine("x is less than or equal to 5")

End If

3. If...ElseIf...Else Statement:
If condition1 Then

' Statements to execute if condition1 is True Example:


ElseIf condition2 Then Dim x As Integer = 10
' Statements to execute if condition2 is True If x > 10 Then
Else Console.WriteLine("x is
greater than 10")
' Statements to execute if neither condition1 nor
condition2 is True ElseIf x = 10 Then
End If Console.WriteLine("x is
equal to 10")
In this form, multiple conditions can be evaluated in
sequence. If condition1 is True, the corresponding Else
statements are executed. If condition1 is False but
condition2 is True, the statements within the ElseIf block areConsole.WriteLine("x
executed. If neither condition1
is
nor condition2 is True, the statements within the Else block
lessare executed.
than 10")

End If
SB CREATIVE
30

Lecture***Data Control

Q1: -Describe the Select Case.


Ans: Select Case statement provides a way to execute different blocks of code based on
the value of an expression. It is similar to a series of If...ElseIf...Else statements but often
offers a more concise and readable syntax, especially when dealing with multiple
conditions. Here's the general syntax of the Select Case statement:

Select Case expression

Case value1

' Statements to execute if expression equals value1

Case value2

' Statements to execute if expression equals value2

Case Else

' Statements to execute if expression doesn't match any previous cases

End Select

Example:

Dim dayOfWeek As Integer = 3 Case 6

Select Case dayOfWeek Console.WriteLine("Friday")

Case 1 Case 7

Console.WriteLine("Sunday") Console.WriteLine("Saturday")

Case 2 Case Else

Console.WriteLine("Monday") Console.WriteLine("Invalid day of


the week")
Case 3
End Select
Console.WriteLine("Tuesday")

Case 4

Console.WriteLine("Wednesday")

Case 5

Console.WriteLine("Thursday")

SB CREATIVE
31

Q2: -Describe the Looping.


Ans: Looping is refers to the repetition of a block of code multiple times until a certain
condition is met. There are three types of Loops, namely the For…..Next loop,
the Do loop, and the While…..End While loop.

1. For...Next Loop:
The For...Next loop executes a block of code a specified number of times. It's commonly
used when you know the number of iterations in advance.
For index As Integer = 1 To 5
Console.WriteLine("Iteration {0}", index)
Next

2. Do...Loop:
The Do...Loop statements execute a block of code repeatedly until a specified condition is
met. There are different variations of Do...Loop, such as Do While...Loop, Do Until...Loop,
and Do...Loop While and Do...Loop Until.
Dim count As Integer = 0
Do While count < 5
Console.WriteLine("Count: {0}", count)
count += 1
Loop

3. While...End While
The While...End While statements execute a block of code as long as a specified condition
is True.
Dim x As Integer = 0
While x < 5
Console.WriteLine("Value of x: {0}", x)
x += 1
End While

SB CREATIVE
32

Lecture***Programs

Q1: -Basic Sum:


Module Module1
Sub Main()
Dim num1 As Integer = 5
Dim num2 As Integer = 3
Dim sum As Integer

sum = num1 + num2

Console.WriteLine("The sum of {0} and {1} is {2}", num1, num2, sum)


End Sub
End Module
Q2: -Basic Multiplication:
Module Module1
Sub Main()
Dim num1 As Integer = 5
Dim num2 As Integer = 3
Dim product As Integer

product = num1 * num2

Console.WriteLine("The product of {0} and {1} is {2}", num1, num2, product)


End Sub
End Module
Q3: -Basic Percentage:
Module Module1
Sub Main()
Dim totalMarks As Double = 500
Dim obtainedMarks As Double = 375
Dim percentage As Double

percentage = (obtainedMarks / totalMarks) * 100

Console.WriteLine("Percentage obtained: {0}%", percentage)


End Sub
End Module

SB CREATIVE

You might also like