Unit 3
Unit 3
Unit 3
classes :
class Definition,
Member functions and Encapsulation,
Constructor and Destructors,
Parameterized Constructor,
Shared Members of vb.net Class,
Inheritance:
Base and Derived Classes,
Base Class Initialization,
MyBase,
Interfaces:
creating interfaces,
using multiple interfaces,
using the Mustinherit keyword(creating abstract classes),
using Mustoverride, Mustoverridable, and Notoverridable,
Polymorphism,
Inheritance based polymorphism,
Interface based polymorphism.
Exception Handling: Try catch statement,
Exception classes in .Net Framework,
Handling Exceptions,
Creating User define Exceptions.
Q1.
Q2.
Q1.
Q2. What is an identifier? Mca 2021 3no.
Q1. What are the major built-in objects in ASP.NET? 6no.
Q1. Mca2020
Q2.
Q1.
Q2. How has exception handling changed in .NET framework. 3no.
Q1.
structures:
A structure in C# is simply a composite data type consisting of a number
elements of other types.
Where the modifier can be private, public, internal or public. The struct is the required
keyword.
For example
The objects of a strcut can be created by using the new operator as follows.
Declare a structures,
structures variable,
structures and array,
structures and objects,
structures and procedures,
structures within structures.
classes :
In VB.NET, a class is a blueprint for creating objects.
It defines a data structure that includes data members (field and
properties) and member functions(methods).
Class can be defined using the class keyword.
It is basic unit of Object-Oriented Programming and represents
real life entities.
class Definition,
A new class requires a class definition. It starts with the class keyword
and contains the class name.
Example:
It can be accessed by all defined objects of the class and operated on the data
member.
And we can access member variables using the public member function.
Encapsulation,
Encapsulation is the concept of wrapping data into a single unit.
It collects data members and member functions into a single unit called class.
Destructors,
In VB.NET, Destructor is a special function that is used to destroy a class object when
the object of the class goes out of scope.
It can be represented as the Finalize() method and does not accept any parameter
nor return any value.
Parameterized Constructor,
In VB.NET, when we pass one or more arguments to a constructor, the constructor is
known as a parameterized constructor.
And the object of the class should be initialized with arguments when it is created.
The new class inherits the properties and methods of the existing class and
can also add new properties and methods of its own.
Derived Class (child) - the class that inherits from another class
Base Class (parent) - the class being inherited from
Types of inheritance
There are the following types of inheritance:
1. Single Inheritance
In multilevel inheritance, a derived class inherits from a base and then the
same derived class acts as a base class for another class.
3. Hierarchical Inheritance
4. Multiple Inheritance
Polymorphism,
Compile-time Polymorphism
Runtime Polymorphism
Compile-time Polymorphism#
Compile-time polymorphism is achieved using method overloading and
operator overloading.
The method overloading means defining multiple methods with the same
name but with different parameters.
Runtime Polymorphism#
Runtime polymorphism is achieved by method overriding.
The method overriding means defining methods in parent and child class with
the same name and signature but different implementation.
Exceptions are nothing but some abnormal and typically an event or condition that
arises during the execution, which may interrupt the normal flow of the program.
Exception handling in .NET is a mechanism that allows you to gracefully handle and
recover from runtime errors or exceptional situations that may occur during the
execution of a program.
The key elements of exception handling in .NET are the try, catch, finally, and throw
statements.
1. Try Statement:
The try block contains the code that might raise an exception.
2. Catch Statement:
The catch block follows the try block and contains the code that handles the
exception.
3. Finally Statement:
The finally block, if present, is executed regardless of whether an exception is
thrown or not.
It is typically used for cleanup operations.
4. Throw Statement:
The throw statement is used to manually throw an exception.
Exception classes in .Net Framework,
In the .Net Framework, exceptions are represented by
classes.
The exception classes in .Net Framework are mainly directly or
indirectly derived from the System.Exception class.
Some of the exception classes derived from the System.Exception class are
the System.ApplicationException and System.SystemException classes
The following table provides some of the predefined exception classes derived
from the Sytem.SystemException class –
Exception Class Description
Handling Exceptions,
Creating User define Exceptions.