Skip to main content

Chapter 1

Visual Programming

PU BCA past exam questions

Past questions and answers

17 questions set from this chapter. Most repeated first.

  • 2024 Spring · 7 marks

Define .net framework. Explain the features of .net framework.

Answer

Definition. The .NET Framework is a software development platform from Microsoft for building and running Windows desktop, web and service applications. It provides a large class library (Framework Class Library, FCL) and a runtime environment, the Common Language Runtime (CLR), which manages execution of programs written in languages such as VB.NET, C# and F#.

Main components

  • CLR (Common Language Runtime): the execution engine. It loads code, compiles MSIL to native code using the JIT compiler, manages memory, enforces security and handles exceptions.
  • FCL / BCL (Base Class Library): a vast set of reusable classes for I/O, collections, strings, database access (ADO.NET), networking, XML, GUI (Windows Forms, WPF) and web (ASP.NET).
  • CTS and CLS: the Common Type System defines the data types shared by all .NET languages; the Common Language Specification defines the rules that languages must follow to interoperate.

Features of the .NET Framework

  1. Language interoperability: code written in one .NET language can be used from another, because all languages compile to the same Intermediate Language (MSIL/CIL).
  2. Platform and CPU independence of IL: compiled assemblies contain IL, which the JIT compiler converts to native code for the machine at run time.
  3. Automatic memory management: the garbage collector reclaims memory of objects that are no longer used, preventing most memory leaks.
  4. Rich class library: ready-made classes reduce development time.
  5. Security: code access security, role-based security and type-safe verification of code.
  6. Exception handling: a uniform, structured (Try...Catch...Finally) mechanism across all languages.
  7. Simplified deployment and versioning: assemblies are self-describing through metadata and manifests, allowing side-by-side versions and avoiding "DLL hell".
  8. Object-oriented and component-based: supports encapsulation, inheritance and polymorphism.
  9. Multithreading and scalability: built-in support for threads and asynchronous programming.
  10. Web and data support: ASP.NET, web services and ADO.NET for database connectivity.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 8 marks

Define variable? Explain the scope and lifetime of variables.

Answer

Variable. A variable is a named memory location that stores a value which may change during program execution. In VB.NET it is declared with the Dim statement, e.g.

Dim age As Integer = 20
Dim name As String = "Ram"

A variable has a name, a data type and a value.

Scope is the region of code in which a variable can be accessed. VB.NET has four levels:

  1. Block scope: declared inside a block such as If, For or While; visible only inside that block.
  2. Procedure scope: declared inside a Sub or Function; visible only within that procedure (local variable).
  3. Module/class scope: declared in a class or module outside any procedure; visible to all procedures of that class (with Private) or beyond it (with Public/Friend).
  4. Namespace scope: declared Public/Friend in a module or class; accessible throughout the namespace/project.

Lifetime is the period during which a variable exists in memory and holds its value.

  • A local variable is created when the procedure is entered and destroyed when it exits; its value is lost between calls.
  • A static variable (Static x As Integer) is local in scope but retains its value between calls for the life of the program.
  • A class/module-level variable lives as long as the object (or, for Shared/module variables, the application) exists.

Example

Public Class Demo
    Dim total As Integer = 0          ' class scope, lives with the object

    Sub Add()
        Dim temp As Integer = 5       ' procedure scope, dies when Add ends
        Static count As Integer = 0   ' retains value across calls
        count += 1
        total += temp
    End Sub
End Class

Scope tells where a variable can be used; lifetime tells how long it exists.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 7 marks

Design and code simple calculator in vb.net with select case.

Answer

Design. Form with two TextBoxes (txtNum1, txtNum2), a ComboBox cboOp holding +, -, *, /, a Button btnCalc (Text "Calculate") and a Label/TextBox lblResult for the output. (Alternatively, four buttons can be used; the logic is the same.)

Code

Public Class frmCalculator
    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim a, b, result As Double

        If Not Double.TryParse(txtNum1.Text, a) OrElse Not Double.TryParse(txtNum2.Text, b) Then
            MessageBox.Show("Please enter valid numbers.")
            Return
        End If

        Select Case cboOp.Text
            Case "+"
                result = a + b
            Case "-"
                result = a - b
            Case "*"
                result = a * b
            Case "/"
                If b = 0 Then
                    MessageBox.Show("Division by zero is not allowed.")
                    Return
                End If
                result = a / b
            Case Else
                MessageBox.Show("Select an operator.")
                Return
        End Select

        lblResult.Text = "Result = " & result.ToString()
    End Sub
End Class

Working. The operator chosen in the ComboBox is the test expression of Select Case; the matching Case block performs the operation and the result is displayed. Case Else handles an invalid selection, and division by zero is checked before dividing.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 8 marks

Explain the different entry-controlled looping statements in Visual Basic with an Example program.

Answer

An entry-controlled loop tests its condition (or range) before executing the body, so the body may execute zero times. VB.NET provides:

1. For...Next - used when the number of iterations is known.

For i As Integer = 1 To 10 Step 1
    ' body
Next

2. For Each...Next - iterates over every element of an array or collection.

For Each item In arr
    ' body
Next

3. While...End While - repeats while the condition is True; the condition is checked first.

While condition
    ' body
End While

4. Do While...Loop - repeats while the condition is True.

Do While condition
    ' body
Loop

5. Do Until...Loop - repeats until the condition becomes True.

Do Until condition
    ' body
Loop

(The Do ... Loop While/Until forms test at the end and are exit-controlled: they run at least once.)

Example program - sum of numbers 1 to 5 using different loops:

Module Module1
    Sub Main()
        Dim i As Integer, sum As Integer = 0

        For i = 1 To 5
            sum += i
        Next
        Console.WriteLine("For loop sum = " & sum)       ' 15

        sum = 0 : i = 1
        While i <= 5
            sum += i
            i += 1
        End While
        Console.WriteLine("While loop sum = " & sum)     ' 15

        sum = 0 : i = 1
        Do Until i > 5
            sum += i
            i += 1
        Loop
        Console.WriteLine("Do Until sum = " & sum)       ' 15

        Console.ReadKey()
    End Sub
End Module

Output: each line prints 15.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 7 marks

Differentiate between Sub routine and Function. Demonstrate the recursive function for finding factorial of number

Answer

Difference between Sub and Function

Sub procedureFunction procedure
Declared with Sub ... End SubDeclared with Function ... End Function
Does not return a valueReturns a single value to the caller
Called as a statement, e.g. Show(5)Can be used in an expression, e.g. x = Fact(5)
No As <type> return typeHas a return type (As Integer) and uses Return
Used to perform an action (display, update)Used to compute and give back a result

Recursive function for factorial. A recursive function calls itself with a smaller argument until a base case is reached: n!=n×(n−1)!n! = n \times (n-1)! with 0!=10! = 1.

Module Module1
    Function Factorial(ByVal n As Integer) As Long
        If n <= 1 Then
            Return 1                    ' base case
        Else
            Return n * Factorial(n - 1) ' recursive call
        End If
    End Function

    Sub Main()
        Console.Write("Enter a number: ")
        Dim num As Integer = Integer.Parse(Console.ReadLine())
        Console.WriteLine("Factorial of " & num & " = " & Factorial(num))
        Console.ReadKey()
    End Sub
End Module

For input 5 the calls expand as 5×4×3×2×1=1205 \times 4 \times 3 \times 2 \times 1 = 120, so the output is Factorial of 5 = 120.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 8 marks

Define procedure? How exceptions are handled in VB.NET? Does VB support multiple catch? Demonstrate it.

Answer

Procedure. A procedure is a named block of code that performs a specific task and can be called repeatedly from other parts of a program. VB.NET has Sub procedures (do not return a value) and Function procedures (return a value), and property procedures.

Exception handling. An exception is a run-time error (e.g. divide by zero, invalid conversion, file not found). VB.NET handles them with structured exception handling:

Try
    ' code that may cause an exception
Catch ex As ExceptionType
    ' handler
Finally
    ' always executed (cleanup)
End Try
  • Try encloses the risky code.
  • Catch handles a particular exception type; control moves to it when an exception occurs.
  • Finally always runs, whether or not an exception occurred (e.g. to close files/connections).
  • Throw raises an exception explicitly.

Multiple Catch. Yes, VB.NET supports multiple Catch blocks. They are checked in order, so more specific exceptions must come before the general Exception.

Module Module1
    Sub Main()
        Try
            Console.Write("Enter a: ")
            Dim a As Integer = Integer.Parse(Console.ReadLine())
            Console.Write("Enter b: ")
            Dim b As Integer = Integer.Parse(Console.ReadLine())
            Console.WriteLine("a / b = " & (a \ b))
        Catch ex As DivideByZeroException
            Console.WriteLine("Cannot divide by zero.")
        Catch ex As FormatException
            Console.WriteLine("Please enter integers only.")
        Catch ex As Exception
            Console.WriteLine("Error: " & ex.Message)
        Finally
            Console.WriteLine("Program finished.")
        End Try
        Console.ReadKey()
    End Sub
End Module

Entering 5 and 0 prints the divide-by-zero message; entering abc prints the format message; Finally runs in all cases.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 8 marks

What is Classes and Object? WAP using classes and object to find a area of rectangle

Answer

Class. A class is a blueprint or template that defines the data (fields/properties) and behaviour (methods) common to a group of objects.

Object. An object is an instance of a class; it occupies memory and has its own copy of the class's data. Objects are created with the New keyword.

Program: area of a rectangle using a class and object

Public Class Rectangle
    Private length As Double
    Private breadth As Double

    Public Sub New(l As Double, b As Double)   ' constructor
        length = l
        breadth = b
    End Sub

    Public Function Area() As Double
        Return length * breadth
    End Function
End Class

Module Module1
    Sub Main()
        Console.Write("Enter length: ")
        Dim l As Double = Double.Parse(Console.ReadLine())
        Console.Write("Enter breadth: ")
        Dim b As Double = Double.Parse(Console.ReadLine())

        Dim r As New Rectangle(l, b)            ' object creation
        Console.WriteLine("Area of rectangle = " & r.Area())
        Console.ReadKey()
    End Sub
End Module

For length 5 and breadth 4, the output is Area of rectangle = 20, since A=l×bA = l \times b.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 7 marks

Define Timer. Explain the properties, methods and events of timer.

Answer

Timer. The Timer is a Windows Forms control that raises an event at regular intervals. It is invisible at run time and is used for clocks, animation, auto-refresh and timed tasks.

Properties

  • Enabled: True/False; turns the timer on or off.
  • Interval: time between ticks in milliseconds (1000 = 1 second).
  • Name, Tag: identifier and user data.

Methods

  • Start(): starts the timer (sets Enabled = True).
  • Stop(): stops the timer (sets Enabled = False).
  • Dispose(): releases resources used by the timer.

Events

  • Tick: occurs each time the Interval elapses; the code to be run periodically is written here.

Example: digital clock

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Timer1.Interval = 1000
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    lblTime.Text = DateTime.Now.ToString("hh:mm:ss tt")
End Sub

Every second the Tick event fires and the label shows the current time. Timer1.Stop() in a button click would halt the clock.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 7 marks

Define graphics? List and explain different types of Graphics available in VB.NET.

Answer

Graphics. Graphics means drawing shapes, lines, text and images on a surface such as a form, PictureBox or printer. In VB.NET this is done through GDI+ (namespace System.Drawing), mainly using the Graphics class obtained from a control's Paint event or CreateGraphics().

Types of graphics available

  1. Lines: DrawLine(pen, x1, y1, x2, y2).
  2. Rectangles and squares: DrawRectangle, FillRectangle.
  3. Ellipses and circles: DrawEllipse, FillEllipse.
  4. Arcs, pies and curves: DrawArc, DrawPie, FillPie, DrawCurve.
  5. Polygons: DrawPolygon, FillPolygon (uses an array of points).
  6. Text: DrawString(text, font, brush, x, y).
  7. Images: DrawImage(image, x, y) for bitmaps and pictures.

Supporting objects: Pen (outline colour/width), Brush (SolidBrush, HatchBrush, LinearGradientBrush for fills), Font, Color.

Example

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    Dim g As Graphics = e.Graphics
    Dim p As New Pen(Color.Blue, 2)
    g.DrawLine(p, 10, 10, 200, 10)
    g.DrawRectangle(p, 10, 30, 100, 60)
    g.FillEllipse(Brushes.Red, 130, 30, 80, 60)
    g.DrawString("Hello", New Font("Arial", 14), Brushes.Black, 10, 110)
End Sub

The graphics can be classified more broadly as vector graphics (lines, shapes, text drawn by GDI+) and raster/bitmap graphics (images drawn with DrawImage).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 7 marks

Define File handling? How can we read and write to and from a text file. Illustrate with code snippet.

Answer

File handling. File handling means creating, opening, reading, writing, updating and closing files so that data persists permanently on disk after the program ends. In VB.NET the System.IO namespace provides classes such as File, StreamReader, StreamWriter, FileStream, Directory.

Writing to a text file uses StreamWriter:

Imports System.IO

Dim sw As New StreamWriter("C:\data\student.txt")   ' overwrites; use True to append
sw.WriteLine("Ram Sharma")
sw.WriteLine("BCA 4th Semester")
sw.Close()

Reading from a text file uses StreamReader:

Dim sr As New StreamReader("C:\data\student.txt")
Dim line As String
Do
    line = sr.ReadLine()
    If line IsNot Nothing Then Console.WriteLine(line)
Loop Until line Is Nothing
sr.Close()

Shortcuts with the File class

File.WriteAllText("C:\data\a.txt", "Hello")       ' write
File.AppendAllText("C:\data\a.txt", " World")     ' append
Dim s As String = File.ReadAllText("C:\data\a.txt") ' read all

Notes. Use File.Exists(path) before reading; close streams (or use Using ... End Using) to release the file; wrap the code in Try...Catch to handle FileNotFoundException and IOException.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 8 marks

Design a form for login and sign up with username and password. Write the complete code snippet for login if username and password match else shows the error message otherwise if user clicks on sign up button it should redirect to sign up page where user can create username and password. Use the database name BCA and Table name tbl User detail.

Answer

Design. Two forms are used.

  • frmLogin: Labels, TextBox txtUser, TextBox txtPass (PasswordChar = *), Buttons btnLogin and btnSignUp.
  • frmSignUp: TextBox txtNewUser, txtNewPass, txtConfirm, Button btnCreate.

Database. Database BCA, table tblUserDetail:

CREATE TABLE tblUserDetail (
    UserName VARCHAR(50) PRIMARY KEY,
    Password VARCHAR(50) NOT NULL
);

Code for frmLogin

Imports System.Data.SqlClient

Public Class frmLogin
    Dim conStr As String = "Data Source=.\SQLEXPRESS;Initial Catalog=BCA;Integrated Security=True"

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Using con As New SqlConnection(conStr)
            Dim cmd As New SqlCommand("SELECT COUNT(*) FROM tblUserDetail WHERE UserName=@u AND Password=@p", con)
            cmd.Parameters.AddWithValue("@u", txtUser.Text)
            cmd.Parameters.AddWithValue("@p", txtPass.Text)
            Try
                con.Open()
                If Convert.ToInt32(cmd.ExecuteScalar()) > 0 Then
                    MessageBox.Show("Login successful")
                Else
                    MessageBox.Show("Invalid username or password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Using
    End Sub

    Private Sub btnSignUp_Click(sender As Object, e As EventArgs) Handles btnSignUp.Click
        Dim f As New frmSignUp()
        f.Show()
        Me.Hide()
    End Sub
End Class

Code for frmSignUp

Imports System.Data.SqlClient

Public Class frmSignUp
    Dim conStr As String = "Data Source=.\SQLEXPRESS;Initial Catalog=BCA;Integrated Security=True"

    Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
        If txtNewUser.Text = "" OrElse txtNewPass.Text = "" Then
            MessageBox.Show("All fields are required")
            Return
        End If
        If txtNewPass.Text <> txtConfirm.Text Then
            MessageBox.Show("Passwords do not match")
            Return
        End If
        Using con As New SqlConnection(conStr)
            Dim cmd As New SqlCommand("INSERT INTO tblUserDetail(UserName, Password) VALUES(@u,@p)", con)
            cmd.Parameters.AddWithValue("@u", txtNewUser.Text)
            cmd.Parameters.AddWithValue("@p", txtNewPass.Text)
            Try
                con.Open()
                cmd.ExecuteNonQuery()
                MessageBox.Show("Account created. Please log in.")
                frmLogin.Show()
                Me.Close()
            Catch ex As SqlException
                MessageBox.Show("Username already exists or database error: " & ex.Message)
            End Try
        End Using
    End Sub
End Class

Parameterised queries (@u, @p) are used to prevent SQL injection. In real systems the password should be stored as a hash.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 8 marks

Define forms. Differentiate between MDI and SDI. How can we control one form from another form. Illustrate with code snippet.

Answer

Form. A form is a window that forms the user interface of a Windows application. It is a container on which controls (buttons, textboxes, labels etc.) are placed, and it has properties (Text, BackColor, Size), methods (Show, Hide, Close) and events (Load, Click, FormClosing).

MDI vs SDI

SDI (Single Document Interface)MDI (Multiple Document Interface)
Each form is an independent window; only one document per windowA parent form contains several child forms inside it
Child windows are not confined to a parentChild forms stay within the parent's client area
Each window has its own menuParent's menu is shared/merged with the active child
Example: NotepadExample: Excel (older versions), Visual Studio
Simple to buildSet parent's IsMdiContainer = True and child's MdiParent = parent

Controlling one form from another. Create an instance of the other form and use its public members, or open/close/hide it.

' Form1: open Form2 and pass data
Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
    Dim f2 As New Form2()
    f2.lblName.Text = txtName.Text     ' control must be Public (Modifiers = Public)
    f2.Show()                          ' or f2.ShowDialog() for modal
    Me.Hide()
End Sub

' Form2: control the first form
Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
    Form1.Show()
    Me.Close()
End Sub

Other ways: a public method/property in the target form (f2.SetName("Ram")), or a constructor taking parameters. For MDI: child.MdiParent = Me : child.Show().

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 8 marks

Define Database handling? Explain the architecture of ADO.Net in detail.

Answer

Database handling. Database handling means connecting an application to a database and performing operations on it: storing, retrieving, inserting, updating and deleting data. In .NET this is done using ADO.NET.

ADO.NET (ActiveX Data Objects for .NET) is the .NET data-access technology. It works in a disconnected manner and supports XML.

Architecture. ADO.NET has two main parts.

1. .NET Data Provider (connected components; e.g. System.Data.SqlClient for SQL Server, OleDb, Odbc)

  • Connection: establishes a link to the data source (SqlConnection with a connection string); methods Open(), Close().
  • Command: executes SQL statements or stored procedures (SqlCommand): ExecuteReader(), ExecuteNonQuery(), ExecuteScalar().
  • DataReader: fast, forward-only, read-only stream of rows from the database; needs an open connection.
  • DataAdapter: acts as a bridge between the database and a DataSet; Fill() loads data into the DataSet and Update() writes changes back. It holds Select, Insert, Update and Delete commands.

2. DataSet (disconnected component)

  • An in-memory cache of data independent of the data source. It contains a collection of DataTables (with DataRows, DataColumns), constraints and DataRelations.
  • Data can be edited offline and then synchronised through the DataAdapter; it can be read/written as XML.

Flow:

Application↔DataSet↔DataAdapter↔Command↔Connection↔Database\text{Application} \leftrightarrow \text{DataSet} \leftrightarrow \text{DataAdapter} \leftrightarrow \text{Command} \leftrightarrow \text{Connection} \leftrightarrow \text{Database}

while a DataReader connects the application directly to the Command for read-only access.

Advantages: disconnected access reduces server load and improves scalability, it is language independent, XML based, and offers strong data-binding support to controls.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 7 marks

How the database is accessed using server explorer? Write down the code snippet for database connectivity Using ADO.net with databases.

Answer

Accessing a database using Server Explorer

  1. Open Visual Studio and choose View > Server Explorer.
  2. Right-click Data Connections and select Add Connection.
  3. Choose the data source (e.g. Microsoft SQL Server), enter the server name, authentication (Windows or SQL Server) and select the database name.
  4. Click Test Connection, then OK. The database appears under Data Connections.
  5. Expand it to view Tables, Views and Stored Procedures; right-click a table and choose Show Table Data to view or edit records, or Open Table Definition to change the design.
  6. Drag a table onto a form (or use the connection's Properties to copy the connection string) to create a bound DataGridView, DataSet and adapter automatically.

Code for connectivity using ADO.NET

Imports System.Data.SqlClient

Public Class Form1
    Dim conStr As String = "Data Source=.\SQLEXPRESS;Initial Catalog=BCA;Integrated Security=True"

    Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
        Using con As New SqlConnection(conStr)
            Try
                Dim da As New SqlDataAdapter("SELECT * FROM Student", con)
                Dim ds As New DataSet()
                da.Fill(ds, "Student")
                DataGridView1.DataSource = ds.Tables("Student")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Using
    End Sub

    Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
        Using con As New SqlConnection(conStr)
            Dim cmd As New SqlCommand("INSERT INTO Student(Name, Age) VALUES(@n, @a)", con)
            cmd.Parameters.AddWithValue("@n", txtName.Text)
            cmd.Parameters.AddWithValue("@a", Integer.Parse(txtAge.Text))
            con.Open()
            cmd.ExecuteNonQuery()
            MessageBox.Show("Record inserted")
        End Using
    End Sub
End Class

The connection string identifies the server, database and security mode; the adapter fills a DataSet shown in the grid, and a Command executes the insert.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 5 marks

Write short notes on: Constructor and Destructor in vb.net

Answer

Constructor. A constructor is a special method named New that runs automatically when an object is created. It initialises the object's fields. It has no return type and can be overloaded (different parameter lists).

Public Class Student
    Private name As String
    Private roll As Integer

    Public Sub New()                       ' default constructor
        name = "Unknown" : roll = 0
    End Sub

    Public Sub New(n As String, r As Integer)   ' parameterised constructor
        name = n : roll = r
    End Sub
End Class

Dim s As New Student("Ram", 1)

Destructor. A destructor is called when an object is destroyed, to release resources. In VB.NET it is written by overriding Finalize (Protected Overrides Sub Finalize()), which the garbage collector calls; the exact time is not predictable. For deterministic cleanup, implement IDisposable and the Dispose method, used with Using.

Protected Overrides Sub Finalize()
    ' release unmanaged resources
    MyBase.Finalize()
End Sub

Key differences: a constructor initialises and can take parameters and be overloaded; a destructor cleans up, takes no parameters, cannot be overloaded and is invoked by the garbage collector.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 5 marks

Write short notes on: String and Related Functions

Answer

A string is a sequence of characters, represented by the String class in VB.NET. Strings are immutable: every modification creates a new string. Common functions and methods:

Function / MethodPurposeExample
Len(s) / s.Lengthnumber of charactersLen("Nepal") = 5
UCase(s) / s.ToUpper()convert to upper case"nepal" -> "NEPAL"
LCase(s) / s.ToLower()convert to lower case"NEPAL" -> "nepal"
Left(s, n)first n charactersLeft("Kathmandu", 4) = "Kath"
Right(s, n)last n charactersRight("Kathmandu", 4) = "andu"
Mid(s, start, n) / s.Substring(i, n)part of a stringMid("Kathmandu", 5, 3) = "man"
Trim(s) / s.Trim()remove leading/trailing spaces" hi " -> "hi"
InStr(s, t) / s.IndexOf(t)position of a substringInStr("Nepal","p") = 3
s.Replace(a, b)replace text"cat".Replace("c","b") = "bat"
s.Split(c)split into an array"a,b".Split(","c)
String.Concat, &join strings"A" & "B" = "AB"
StrReverse(s)reverse"abc" -> "cba"
s.Contains(t), s.StartsWith(t), s.EndsWith(t)testsreturn Boolean
String.Compare(a, b)compare two strings0 if equal
Dim s As String = "  Education Nepal "
Console.WriteLine(s.Trim().ToUpper())   ' EDUCATION NEPAL

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 Spring · 5 marks

Write short notes on: Abstract class

Answer

An abstract class is a class that cannot be instantiated directly; it is meant to be a base class for other classes. In VB.NET it is declared with the MustInherit keyword. It may contain:

  • abstract members declared with MustOverride (no body); derived classes must implement them using Overrides;
  • ordinary (concrete) methods, fields and properties with implementations, which derived classes inherit.
Public MustInherit Class Shape
    Public MustOverride Function Area() As Double       ' no body

    Public Sub Display()                                ' concrete method
        Console.WriteLine("Area = " & Area())
    End Sub
End Class

Public Class Circle
    Inherits Shape
    Private r As Double
    Public Sub New(r As Double)
        Me.r = r
    End Sub
    Public Overrides Function Area() As Double
        Return Math.PI * r * r
    End Function
End Class

Dim c As New Circle(2)     ' Dim s As New Shape() would be an error
c.Display()

Features: cannot be instantiated; supports inheritance and polymorphism; enforces a common interface on subclasses; a class with a MustOverride member must itself be MustInherit. It is used to share common code while leaving specific behaviour to subclasses.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

Questions from PU BCA 2024 Spring Visual Programming (Pokhara University BCA, Spring 2024), PU BCA 2025 Spring Database Management System (New) (Pokhara University BCA, Spring 2025, new syllabus), PU BCA 2025 Spring Database Management System (Old) (Pokhara University BCA, Spring 2025, old syllabus), PU BCA 2024 Spring Database Management System (Pokhara University BCA, Spring 2024), PU BCA 2025 Spring Computer Graphics and Multimedia Technology (New) (Pokhara University BCA, Spring 2025, new syllabus), PU BCA 2025 Spring Computer Graphics and Multimedia Technology (Old) (Pokhara University BCA, Spring 2025, old syllabus), PU BCA 2024 Spring Computer Graphics and Multimedia Technology (Pokhara University BCA, Spring 2024), PU BCA 2023 Spring Computer Graphics and Multimedia (Pokhara University BCA, Spring 2023), PU BCA 2025 Spring Probability and Statistics (New) (Pokhara University BCA, Spring 2025, new syllabus), PU BCA 2025 Spring Fundamentals of Probability and Statistics (Pokhara University BCA, Spring 2025), PU BCA 2024 Spring Fundamentals of Probability and Statistics (Pokhara University BCA, Spring 2024), PU BCA 2023 Spring Fundamentals of Probability and Statistics (Pokhara University BCA, Spring 2023), PU BCA 2025 Spring Software Engineering (New) (Pokhara University BCA, Spring 2025, new syllabus), PU BCA 2025 Spring Software Engineering (Pokhara University BCA, Spring 2025), PU BCA 2024 Spring Software Engineering (Pokhara University BCA, Spring 2024), PU BCA 2023 Spring Software Engineering (Pokhara University BCA, Spring 2023), PU BCA 2022 Fall Software Engineering (Pokhara University BCA, Fall 2022), PU BCA 2021 Spring Software Engineering (Pokhara University BCA, Spring 2021), PU BCA 2025 Spring Web Technologies II (New) (Pokhara University BCA, Spring 2025, new syllabus), PU BCA 2025 Spring Web Technologies II (Pokhara University BCA, Spring 2025), PU BCA 2024 Spring Web Technologies II (Pokhara University BCA, Spring 2024) and PU BCA 2023 Spring Web Technologies II (Pokhara University BCA, Spring 2023). Answers are written for this site; check them against your class notes.