Wednesday, October 27, 2010

Interview 26/10/2010 bangalore company

1.what is IL ?
2.what is JIT ?
3.What is CLR ?
4.What is Profiler ?
5.What is polymerfisim in C# ?
6.What is difference between virtual and New ?
7.what is dispose ? why it is used ? when it is used ?
8.What is the coding standard of the code are you follow Microsoft coding  standard ?
9.How security maintained by the CLR ?
10.Define your profile(Resume) ?
11.What is Finalize ?
12.What is GC.SuppressFinalize ?
13.What is Idisposable interface ?
 


Q.What is IL ?
Ans- MSIL is a platform independent language meaning that it does not dependent on the type of platform,
all the code written in .Net will first be converted into intermediate language and then .net compiler compiles it and generate a machine language code.
Main advantages of intermediate language
Intermediate language is independent of any language and hence there is possibility to create applications with modules that were written in different programming language supported by .net,
This means that we can develop different modules in an application in different programming language and can compile the application.

Q What's the difference between override and new in C#? 
http://www.dotnetinterviewfaqs.com/difference-between-override-and-new-in-polymorphism.aspx
We can use new or override to rewrite a method in an child class.
But what is the difference between new and override?
*****************************************
DerivedType derivedInstance = new DerivedType();
BaseType baseVar = derivedInstance;
baseVar.CallMethod();
------------------------------------------------------------------------
If the DerivedType.CallMethod() is defined as "new", the above code will
code the BaseType version. If it is defined as "override", it wil call the
DerivedType version.

If you are using inheritance to get polymorphism, you probably want
override.
**************************************************
http://bytes.com/topic/c-sharp/answers/261357-what-difference-between-new-override

7 comments:

  1. What is the difference between using virtual and new?
    Ans-
    The Virtual keyword (used in the base class) lets a method be overridden (by using override in the derived class) such that if you declare an object of a base type, and instantiate it of a derived type, then calling the virtual method will call the derived type's method, not the base type. This is polymorphism.

    The new keyword (used in the derived class) lets you hide the implementation of a base method such that when you declare and instantiate an object of the same type, the method of that type is called. There is no polymorphism here.

    I think the best way to explain this is via a code sample that shows the different effects of using virtual vs. new. Say you have the following two classes:

    public class MyBase
    {
    public virtual string MyVirtualMethod()
    {
    return "Base";
    }

    public string MyNonVirtualMethod()
    {
    return "Base";
    }
    } //end of sub class

    public class MyDerived : MyBase
    {
    public override string MyVirtualMethod()
    {
    return "Derived";
    }

    public new string MyNonVirtualMethod()
    {
    return "Derived";
    }
    } //end of sub class

    This has two classes, MyBase and MyDerived. For illustration, the classes each only have two methods. For comparison, MyBase has one method virtual, and one not. Likewise, MyDerived overrides the virtual method and hides the non-virtual. The following code snippet shows three separate cases. Note that the virtual-new keywords affect the value of MyNonVirtualMethod based on whether the object is declared as type MyBase or MyDerived.

    MyBase m1 = new MyDerived();
    Console.WriteLine("MyVirtualMethod='" + m1.MyVirtualMethod() + "', MyNonVirtualMethod='" + m1.MyNonVirtualMethod() + "'");
    // Returns: MyVirtualMethod='Derived', MyNonVirtualMethod='Base'

    MyDerived md = new MyDerived();
    Console.WriteLine("MyVirtualMethod='" + md.MyVirtualMethod() + "', MyNonVirtualMethod='" + md.MyNonVirtualMethod() + "'");
    // Returns: MyVirtualMethod='Derived', MyNonVirtualMethod='Derived'

    Note that in the first case, where we declare the object of type MyBase yet instantiate it to type MyDerived, calling MyNonVirtual method is called on the declared type. In the second case, it is called on the Instantiated type.

    These concepts are very common when declaring an array of base objects, and then cycling through the array and calling virtual members. A classic example is making an array of Shape objects, calling the GetArea() method on each one, and it correctly returning the area for that shape.

    ReplyDelete
  2. Q-What's the difference between override and new in C#?
    ANS-
    http://www.dotnetinterviewfaqs.com/difference-between-override-and-new-in-polymorphism.aspx

    ReplyDelete
  3. Q-what is the diff between virtual class and abstract class?
    ANS-
    http://www.dotnetspider.com/forum/181568-what-diff-between-virtual-class-abstract-class.aspx

    ReplyDelete
  4. Q-Virtual Function Vs Abstract Function ?
    ANS-
    Both Virtual Function & Abstract Function achieves the same functionality.

    While declaring the Abstract Function in the Base class we don’t have to write any code in its body but in case of Virtual function we can write the body, but when we inherit the Abstract/Virtual Function in our Child Class by using the override keyword it overrides the base class’s function.

    ReplyDelete
  5. Q-what is the difference between Abstract class and interface ?
    ANS-
    Hi,
    In abstract class,we can have both method abstract method(must not be defined) as well as non-abstract methods whereas In interface all methods must be abstract method only.

    In interface you can declare only constant variable whereas In abstract method you can declare constant as well as normal variable also.

    Interface is also called as fully abstract class whereas Abstract class is called as partial abstract class.

    Hope this information is relevant to you.

    ReplyDelete
  6. Hai

    Abstract Class vs Interface

    I am assuming you are having all the basic knowledge of abstract and interface keyword. I am just briefing the basics.

    We can not make instance of Abstract Class as well as Interface.

    Here are few differences in Abstract class and Interface as per the definition.

    Abstract class can contain abstract methods, abstract property as well as other members (just like normal class).

    Interface can only contain abstract methods, properties but we don’t need to put abstract and public keyword. All the methods and properties defined in Interface are by default public and abstract.

    ReplyDelete
  7. Q.Difference between static class and abstract class ?
    Ans-
    An abstract class is one which can't be directly instantiated. It
    usually has some abstract methods which must be implemented by classes
    further down the hierarchy:

    public abstract class Foo
    {
    public abstract void DoSomething();

    public void NormalMethod()
    {
    DoSomething();
    }
    }

    A static class is one which can never be instantiated. You can't use
    this as the type of a parameter, or a variable, or a type parameter.
    It has no constructors (unlike normal classes, which gain a public
    parameterless constructor automatically if you don't specify any
    constructors). It's not allowed to have any instance members. It's
    usually used for "helper methods". Extension methods (new to C# 3.0)
    have to be in non-nested static classes.

    public static class StringUtil
    {
    public static string Reverse(string original)
    {
    // Whatever
    }
    }

    ReplyDelete