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 is object pool in .net?

883


Why data types are important in c#?

877


What is a dbml?

847


Are arrays immutable c#?

963


Explain the feature of c# language?

848


Will the following code compile and run?

939


How will you allow a class to be inherited, but prevent the method from being over-ridden?

931


How to find type of variable?

918


If you define a user defined data type by using the class keyword, is it a value type or reference type?

833


What is the symbol used for in c#?

892


Does c# support properties of array types?

880


Is string passed by reference in c#?

861


what is c# command?

931


What tool we have to use to install assembli in gac folder.

857


How to implement an object pool in c#.net.

995