Thursday, 24 November 2011

OOPS interview questions for dotnet(c#.net)



1.     You have one base class virtual function how will call that function from derived class?
Answer :

        class a
        {
            public virtual int m()
            {
                return 1;
            }
        }
        class b : a
        {
            public int j()
            {
                return m();
            }
        }

2. Can we call a base class method without creating instance?
Answer :

Its possible If its a static method.
Its possible by inheriting from that class also.
Its possible from derived classes using base keyword. 

3. What is Method Overriding? How to override a function in C#?
Answer :

Use the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method.
You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override 

4. What’s an abstract class?
Answer :

A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation. 

5. When do you absolutely have to declare a class as abstract?
Answer :
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract. 

6. What is an interface class?

Answer :

Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes. 

No comments:

Post a Comment

Please Give Your Valuable Comments on this Topic