Q1:What is polymorphisms?
Ans: Polymorphism is one of the very basic question for the interviewers. To answer what is Polymorphism, The most common answer we get is one interface multiple method or multiple form. We declare several method with same name but with different parameter is the easiest example of polymorphisms also known as function overloading.
Following is the example of function overloading:
Q2:What is abstract method?
Ans:Abstract method has no implementation. The class that inherit abstract class have to implement all the abstract method in the derived class.
Following is the example of the abstract method:
Q3:What is static properties of a class?
Ans: In C# a static class is same as a non static class but it is not possible to create instance of the static class. We access static class by the name of static class dot static class function or properties name.
Example: Helper.Save(); Static class does not have instance variable. Normally static class handle input variable and performs some operations. Static class remain life time of the application.
Static member can be declare in non static class. Static member is always callable by class name. Important properties to remember that static member cannot access the non static properties of the class.
Q4: What is difference between encapsulation and abstraction?
Ans: Abstraction means showing that is only important to developer. The concepts of abstraction suggest to show only minimal things to the end developer when developing software. Encapsulation described as hiding complexity of code to the developer. Insertion could be implement in different way by using array or list but that should not a problem for the end user. End user just call the method and get the expected output and don't need think about the implementation as it is hide by the concepts encapsulation.
Ans: Polymorphism is one of the very basic question for the interviewers. To answer what is Polymorphism, The most common answer we get is one interface multiple method or multiple form. We declare several method with same name but with different parameter is the easiest example of polymorphisms also known as function overloading.
Following is the example of function overloading:
using System;
class Calculator
{
static void Add(int x,int y)
{
Console.WriteLine("result is:"+(x+y));
}
static void Add(int x,int y,int z)
{
Console.WriteLine("result is:"+(x+y+z));
}
static void Add()
{
Console.WriteLine("Invalid number");
}
}
Following is the example of overriding also known as virtual method:
using System;
class Vehicle
{
protected decimal avgSpeed;
// Declared virtual so it can be overridden.
public virtual decimal Speed()
{
return avgSpeed;
}
}
class Car : Vehicle
{
protected decimal avgSpeed;
protected decimal horsePower;
// Declared virtual so it can be overridden.
public override decimal Speed()
{
return avgSpeed*horsePower;
}
}
The override function should be define virtual.
Polymorphisms could be understand easily if we understand function overloading and overriding.
Operator overloading could be another example of polymorphisms.
Q2:What is abstract method?
Ans:Abstract method has no implementation. The class that inherit abstract class have to implement all the abstract method in the derived class.
Following is the example of the abstract method:
abstract class Vehicle
{
abstract public void wheels();
abstract public int brakes(int brakes);
abstract public int speed();
}
class Car : Vehicle
{
override public void wheels()
{
// Initialization code goes here.
}
override public int brakes(int brakes)
{
// Initialization code goes here.
}
override public public int speed()
{
// Initialization code goes here.
}
}
Q3:What is static properties of a class?
Ans: In C# a static class is same as a non static class but it is not possible to create instance of the static class. We access static class by the name of static class dot static class function or properties name.
Example: Helper.Save(); Static class does not have instance variable. Normally static class handle input variable and performs some operations. Static class remain life time of the application.
Static member can be declare in non static class. Static member is always callable by class name. Important properties to remember that static member cannot access the non static properties of the class.
Q4: What is difference between encapsulation and abstraction?
Ans: Abstraction means showing that is only important to developer. The concepts of abstraction suggest to show only minimal things to the end developer when developing software. Encapsulation described as hiding complexity of code to the developer. Insertion could be implement in different way by using array or list but that should not a problem for the end user. End user just call the method and get the expected output and don't need think about the implementation as it is hide by the concepts encapsulation.
