Answer: A property with abstract keyword is considered as abstract property. An abstract property cannot have any implementation in the class. In derived classes you must have to write their own implementation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
abstract class Employee
{
private string fName = string.Empty;
private string lName = string.Empty;
public string FirstName
{
get
{
return fName;
}
set
{
fName = value;
}
}
public string LastName
{
get
{
return lName;
}
set
{
lName = value;
}
}
}
// FullName is abstract
public abstract string FullName
{
get;
}
}
class Company: Employee
{
// Overiding the FullName abstract property derived from employee class
public override string FullName
{
get
{
return "Mr. " + FirstName + " " + LastName;
}
}
}
class Main
{
public static void Main()
{
Company CompanyObj = new Company();
CompanyObj.FirstName = "Satish";
CompanyObj.LastName = "Reddy";
Console.WriteLine("Employee Full Name is : " + CompanyObj.FullName);
}
}
Asked In: Many Interviews |
Alert Moderator