Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views5 pages

Dot Net

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

1.

Define inheritance
o Inheritance is a fundamental concept in object-oriented programming
(OOP). It allows a new class (called the subclass or derived class) to
inherit properties and behaviors (i.e., fields and methods) from an existing
class (called the base class or parent class).
o The key idea behind inheritance is to create a hierarchy of classes where
more specific classes (subclasses) can reuse and extend the functionality of
more general classes (base classes).
o For example, consider a base class called Vehicle with properties
like make, model, and methods like startEngine(). You can create
subclasses like Car, Motorcycle, and Truck that inherit these properties and
methods.
2. What is Exception
o An exception is an unexpected event or error that occurs during program
execution. Exceptions disrupt the normal flow of code.
o In programming languages like C# or Java, exceptions are represented as
objects. When an exceptional condition occurs (e.g., division by zero, file
not found), an exception object is thrown.
o Exception handling allows you to catch and handle these exceptions
gracefully. Common exception classes include System.Exception in C#
and java.lang.Exception in Java.
3. Define CLR

• CLR is a component of the .NET Framework. It provides an execution


environment for managed code (code written in languages like C#, VB.NET, etc.).
• Key features of CLR:
o Just-In-Time (JIT) Compilation: Converts IL (Intermediate Language)
code into native machine code during runtime.
o Memory Management: Handles memory allocation, garbage collection,
and object lifetime.
o Security: Enforces type safety, code access security, and role-based
security.
o Exception Handling: Manages exceptions and stack unwinding.
o Thread Management: Supports multithreading and synchronization.
o Metadata: Stores type information, method signatures, and other
metadata.
o Base Class Library (BCL): Provides a set of reusable classes and functions
4. What is framework?
o A framework is a reusable set of libraries, tools, and conventions that
provide a foundation for building software applications.
o Frameworks offer predefined structures, guidelines, and components to
simplify development tasks.
o Examples include the .NET Framework, Java Spring Framework, and Ruby
on Rails.
5. Define polymorphism
• Polymorphism allows objects of different classes to be treated as objects
of a common base class.
• Two types of polymorphism:
o Compile-time (Static) Polymorphism: Achieved through method
overloading and operator overloading.
o Runtime (Dynamic) Polymorphism: Achieved through method
overriding (using inheritance and virtual/override keywords).

6. Define overloading
• Method overloading allows defining multiple methods with the same
name but different parameters (different number or types of parameters).
• Example:
class Calculator
{
public int Add(int a, int b) { / implementation / }
public double Add(double a, double b) { / implementation / }
}
7. Explain functions and Its types?
• Functions (also known as methods) are blocks of code that perform specific tasks.
• Types of functions:
o Built-in Functions: Provided by the programming language
(e.g., Math.sqrt() in JavaScript).
o User-Defined Functions: Created by developers to perform custom
operations.
o Recursive Functions: Call themselves during execution.
o Lambda (Anonymous) Functions: Short, inline functions without a name.
o Higher-Order Functions: Functions that take other functions as
arguments.
8. What is mean by bug and error?
• A bug refers to a flaw or defect in a program that causes it to behave incorrectly
or unexpectedly.
• An error is a deviation from the expected behavior due to incorrect code, invalid
input, or other issues.
• Bugs can lead to errors, but not all errors are necessarily bugs (some may be
caused by external factors).
9. Describe public, private and protected with suitable example?
• These modifiers control the visibility and accessibility of class members
(fields, methods, properties):
o Public: Accessible from any code (within or outside the class).
o Private: Accessible only within the same class.
o Protected: Accessible within the same class and its subclasses (derived
classes).
10. Explain file Stream?

• FileStream is a class in C# (part of the .NET Framework) that provides a


way to read from or write to files.
• It allows low-level access to files, enabling you to work with raw bytes or blocks of
data.
• Key points about FileStream:
o It supports both synchronous and asynchronous operations.
o You can open a file for reading, writing, or both.
o It provides methods for reading and writing bytes, seeking within the file,
and managing file access.
11. What are the types of inheritance?

• Inheritance allows a class to inherit properties and behaviors from another class.
There are several types of inheritance:
1. Single Inheritance:
▪ A class inherits from only one base class.
▪ Example: class Car : Vehicle { / ... / }
2. Multiple Inheritance (not directly supported in C#):
▪ A class inherits from more than one base class.
▪ Achieved through interfaces or other workarounds.
3. Multilevel Inheritance:
▪ A class inherits from another derived class.
▪ Example: class SportsCar : Car { / ... / }
4. Hierarchical Inheritance:
▪ Multiple classes inherit from a single base class.
▪ Example: class Motorcycle : Vehicle { / ... / }
12. Explain finally statement with syntax and example.
The `finally` block ensures specific code executes regardless of whether an exception
occurs or not. Here's a concise breakdown:
Syntax:
try {
} catch (Exception^ e) {
} finally {
}
Explanation:
- The `finally` block follows the `try` and `catch` blocks.
- It ensures the execution of its code, irrespective of exceptions.
- Even if an exception is caught and handled, the code inside `finally` will still execute.
- It's commonly used for cleanup tasks, like releasing resources or closing files, ensuring
their execution regardless of exceptions.
Example (C++/CLI):
try {
} catch (Exception^ e) {
} finally { }
13. Explain .net framework?
The .NET Framework is a software development platform developed by
Microsoft. It provides a runtime environment and a set of libraries and tools for building
and running applications on Windows operating systems. Here are the key points:
1. Common Language Runtime (CLR):
o The CLR manages the execution of code written in languages like C#, F#,
and Visual Basic.
o It handles memory management, security, exception handling, and thread
management.
o Developers write code in high-level languages, and the CLR compiles it to
native machine code during runtime.
2. .NET Framework Class Library (FCL):
o The FCL offers a rich collection of pre-built functions and classes.
o Developers use these libraries to create desktop, web, mobile, and gaming
applications.
o It saves time by providing ready-made components for common tasks.
3. Language Interoperability:
o .NET supports various programming languages.
o Developers can choose their preferred language (e.g., C# or VB.NET) while
still using the same framework.
o This flexibility allows teams to collaborate effectively.
14. Explain function of CLR?
The Common Language Runtime (CLR) serves as the virtual machine component
of the .NET Framework. It provides several essential functions:

1. Execution of Managed Code: The CLR executes managed code written in languages
such as C#, VB.NET, and F#. It converts the Intermediate Language (IL) code into
machine code via Just-In-Time (JIT) compilation and manages memory, thread execution,
and exception handling.

2. Garbage Collection (GC): CLR includes a garbage collector that automatically manages
memory by reclaiming objects that are no longer in use, thus preventing memory leaks
and reducing manual memory management overhead for developers.

3. Security Management: The CLR enforces security policies to ensure that code runs
securely and safely within the .NET environment. It provides features such as code access
security, role-based security, and validation of code before execution.

These functions collectively enable the CLR to provide a runtime environment for
executing .NET applications efficiently and securely.
15. Explain destructors?
Destructors are special member functions in object-oriented programming
languages like C++ and C#. Here's a concise explanation:

1. Purpose: Destructors are used to perform cleanup tasks when an object is destroyed
or goes out of scope. They're the opposite of constructors, which initialize objects.

2. Execution: In C++, destructors are invoked automatically when an object is destroyed


or goes out of scope. In C#, they are implemented using the `IDisposable` interface and
the `Dispose()` method, which is called explicitly or by using the `using` statement.

4. Usage: Destructors are commonly used to release resources held by an object,


such as closing files, releasing memory, or closing database connections. They
ensure that resources are properly deallocated, preventing memory leaks and
resource exhaustion.
16. what is interface? Give Example
An interface in programming is a blueprint of a class, defining a set of methods or
properties that a class must implement. It establishes a contract for behavior without
specifying the implementation. Here's a concise explanation with an example:

Definition: An interface specifies a contract that a class must adhere to, outlining the
methods or properties it must provide. It establishes a common set of behaviors
without defining how those behaviors are implemented.

interface IPrintable {
void Print();
}

class Document : IPrintable {


public void Print() {
Console.WriteLine("Printing document...");
}
}

class Program {
static void Main(string[] args) {
IPrintable doc = new Document();
doc.Print(); // Output: Printing document...
}
}
In this C# example, `IPrintable` is an interface defining a single method `Print()`. The
`Document` class implements this interface by providing the implementation for the
`Print()` method. The `Program` class demonstrates the usage of the interface by
creating an instance of `Document` through the `IPrintable` interface and calling the
`Print()` method.

You might also like