Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

inheritence in c#

This is a discussion on inheritence in c# within the C# forums, part of the Software Development category; what is 1.virtual 2.override 3.sealed override 4.new...........

Go Back   Geeks Talk > Software Development > C#
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 08-24-2009
Junior Member
 
Join Date: Aug 2009
Location: chennai
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
dprakashraj is on a distinguished road
inheritence in c#

what is
1.virtual
2.override
3.sealed override
4.new........
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-25-2009
Junior Member
 
Join Date: Nov 2007
Posts: 26
Thanks: 2
Thanked 4 Times in 4 Posts
shilpa.c is on a distinguished road
Re: inheritence in c#

All these keywords are used with Methods in class.

1.Virtual: - if you use these keyword with method, the method may be overridden in derived class, not compulsory.
class MyClass
{
public virtual void MyMethod()
{..........}
}

2.Override: - To override a method in derived class this keyword is used. To use this keyword in derived class the method in base class must be declared either with virtual or abstract.

class MyClass
{
public virtual void MyMethod()
{..........}
}
class childClass:MyClass
{
public override void MyMethod()
{..........}
}


3.Sealed Override: - This keyword must be used with a method in derived class only, to avoid overriding in further derived class of this class.To use this keyword in derived class the method in base class must be declared either with override or abstract.if you use this keyword the method can't overriden in further derived class.

class MyClass
{
public virtual void MyMethod()
{..........}
}
class childClass:MyClass
{
public sealed override void MyMethod()
{..........}
}
next if you derive class from this MyClass you can't override MyMethod

4.New - this keyword can be used with any methods to write new definition in derived class, to hide base class methods that is not declared with the keyword virtual or abstract.

class MyClass
{
public void MyMethod()
{..........}
}
class childClass:MyClass
{
public new void MyMethod()
{..........}
}

Last edited by shilpa.c; 08-25-2009 at 04:06 AM.
Reply With Quote
  #3 (permalink)  
Old 10-18-2009
Banned
 
Join Date: Oct 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
rjroking is on a distinguished road
Re: inheritence in c#

still i cant understand......make it more simpilar and give some examples please
Reply With Quote
Reply

  Geeks Talk > Software Development > C#

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -4. The time now is 05:33 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved