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 difference between static and readonly in c#?

1101


Is c# slower than java?

936


Why do I get an error (cs1006) when trying to declare a method without specifying a return type?

975


Is int an object in c#?

953


What is an int c#?

915


what is collections in .net? why we use?

2194


Why do we use constructors in c#?

1188


how to insert the data from the grid view to database table though button click.pls send the answer to mail id suri1319@gmail.com

1956


What are delegate methods?

1018


Can we inherit static class in c#?

1038


When do we generally use destructors to release resources?

984


How main method is called in c#?

1001


How do you declare a method in c#?

999


How do you set a class path?

931


What is an object pool in .net?

1099