Interview question
Interview question
ACCESS MODIFIER
1. Public
- Public member can be accessible in any project.
2. Private
- Members can be accessed within the same class only.
3. Protected
- Members can be accessed only derived class.
4. Internale
- Member can be accessed in same project and same assembly.
MAIN
- Main static mean it is entry point of console application.
OOPS
INHERTANCE
1. What is inheritance?
- One of the most important concepts in object oriented programming is inheritance.
Inheritance allows us to define a class in term of another class.
Inheritance is use to provide the code resuability.
SEALED
2. Can derive class have public modifier when there are no modifiers specified on
the base class?
- No
INTERFACE
11. If 2 interface has same method then how to implement the method?
- Explicit implimentation.
CONSTRUCTOR
1. What is constructor?
- Constructor is special method of class which will invoke automatically whenever
instance or object of is created.
Constructor name should match with class and constructor dose not have any return
type.
2. Type constructor?
-
1. Default Constructor - A Constructor without having any parameters called default
constructor.
2. Parameteries Constructor - A Constructor with atleast one parameter called
parameteries constructor.
3. Copy Constructor - A Constructor is parameteries that contains a parameter as
same type of class called copy constructor. - Porpose (is to initialize new
instance to the values of exsting instance.)
4. Private Constructor - A Constructor with private access modifer called private
Constructor - Porpose (static member) - we can not create object of this class
5. Static Constracturor - A Constructor with static key word called static
constructor - Porpose (static constructor it is use to initialize the static field
of the class)
8. Can we create the object of class if we have only private constructor in class?
- No
16. How can we call one constructor from another in the same class ?
- : This keyword
17. How to call explicitly base class constructor from child class?
- : Base() keyword
DESTRUCTOR
1. What is destructor?
- A destructor runs after a class becomes unreachable it has the special "~'
characters in its name.
POLYMORPHISM
1. What is polymorphism?
- Polymorphism mean one name many form.
Same method name for different purpose called polymorphism.
METHOD OVERLOADING
1. Overloading
- Having two or more different with same name but different parameter in single
class.
Examples,
1.
public class Employee // example its working
{
public int Sum(int a, int b)
{
return a+b;
}
2.
public class Employee // confuse question - answer is not working.
{
public int Sum(int a, int b)
{
return a+b;
}
3.
public class Employee // example its working but it not method overloading - c# is
case sencitive.
{
public int Sum(int a, int b)
{
return a+b;
}
METHOD OVERRIDING
1. What is Overriding?
- A overriding method provide a new implementation of a member that is inherited
from a base class.
A overriding is same name and same parameter but different implementation.
4. Can we use the virtual modifier with the static, abstract, private or override
modifiers.
- No
7. If parent class virtual method and child have same method without override
keyword, Will code be compiled?
- Yes
PARAMS
ABSTRACT