Search This Blog

Q81-Q85

Q81. Can I create object of any type in Using block in C# i.e Can I create object not related to unmanaged resource in using block?
Q82. Write syntax of simple Abstract Class?
Q83. What is inheritance?
Q84. Can we inherit constructor of a base class?
Q85. What are the difference between HttpHandler and Http Module?

=======================================================================
Q81. Can I create object of any type in Using block in C# i.e Can I create object not related to unmanaged resource in using block?

Answer:
 No. We will get error and we have to implement IDisposable interface to make it workable. 

It's saying that "type used in using statement must be implicitly convertible to System.IDisposable". That means, please Implement the IDisposable Interface to keep the class object within the using block. 
But if we have implemented any class like fileread, or reading from DB we might not have seen this error because in those case IDisposable interface is implemented internally  by C#.
=======================================================================
Q82. Write syntax of simple Abstract Class?

Answer:
// C# program to show the
// working of abstract class
using System;

// abstract class 'GeeksForGeeks'
public abstract class GeeksForGeeks {

// abstract method 'gfg()'
public abstract void gfg();
}

// class 'GeeksForGeeks' inherit
// in child class 'Geek1'
public class Geek1 : GeeksForGeeks
{

// abstract method 'gfg()'
// declare here with
// 'override' keyword
public override void gfg()
{
Console.WriteLine("class Geek1");
}
}

// class 'GeeksForGeeks' inherit in
// another child class 'Geek2'
public class Geek2 : GeeksForGeeks
{

// same as the previous class
public override void gfg()
{
Console.WriteLine("class Geek2");
}
}

// Driver Class
public class main_method {

// Main Method
public static void Main()
{

// 'g' is object of class
// 'GeeksForGeeks' class '
// GeeksForGeeks' cannot
// be instantiate
GeeksForGeeks g;

// instantiate class 'Geek1'
g = new Geek1();
// call 'gfg()' of class 'Geek1'
g.gfg();
// instantiate class 'Geek2'
g = new Geek2();
// call 'gfg()' of class 'Geek2'
g.gfg();
}
}

=============================================================================
Q83. What is inheritance?

Answer:
Inheritance is a concept in which you define parent classes and child classes. The child classes inherit methods and properties of the parent class, but at the same time, they can also modify the behavior of the methods if required.
=============================================================================
Q84. Can we inherit constructor of a base class?

Answer:
Drived class can not inherit the constructor of base class but it can invoke the constructor of base class. 
in other words. :
In inheritance, the derived class inherits all the members(fields, methods) of the base class, but derived class cannot inherit the constructor of the base class because constructors are not the members of the class. Instead of inheriting constructors by the derived class, it is only allowed to invoke the constructor of base class.


=============================================================================
Q85. What are the difference between HttpHandler and Http Module?

Answer:
One request can have multiple HTTP Modules associated with it but can be handled by only one HTTP Handler. The type of HTTPHandler is decided by the extention of the request file like .aspx, .asmx. ASP.Net has it's own HTTPHandlers and HTTPModules that are used with client requests

=============================================================================

No comments:

Post a Comment