Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How can you prevent classes to be inherited?

Answer Posted / asit nutiyal(birla)

sealed modifier is used for preventing the accident
inhritance of a class. A sealed class can not be inhrited.

Example :

using system;

sealed class abc
{
protected string str = "";

public virtual void hello()
{
str = " Hi i am not in C#";
}
class xyz : abc //--ERROR--
{
public override void hell0()
{
str = "hi i am in C#";
Console.WriteLine("{0}",str);
}
}
class mainclass
{
public static void Main()
{
xyz x = new xyz();
x.hello();
}
}

Note-> if we run above program thn we will get an error
because we inheit class abc while it is sealed.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by saying a "class is a reference type"?

920


What is default value of enum c#?

902


Do void methods have parameters?

972


What is event delegate in c#?

1097


Contrast between an interface and abstract class?

981


Why we use get and set property in c#?

938


What operators can be used to cast from one reference type to another without the risk of throwing an exception?

914


Explain namespaces in c#.

1011


What are managed providers?

1021


Why do you call it a process? What’s different between process and application in .net, not common computer usage, terminology?

1012


Is predicate a functional interface?

973


What is .net c#?

916


Why are c# strings immutable?

992


How to Show Message box in Metro Style App?

1030


What is the difference between asp net and c#?

929