C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

New Keyword


Posted Date: 10 Aug 2008      Posted By: Supraja Chapram      Member Level: Silver     Points: 1   Responses: 1



I have a code as below
 

Class MomClass()
{ public void method1()
{ console.write("momclass");}
}
Class BabyClass()
{ public new void method1()
{ console.write("babyclass");}
}
static void main()
{
MomClass mc = New BabyClass();
mc.method1();
}


The output : momclass
Here even though the object is MomClass the instantiation is for BabyClass. Then why BabyClass method1() is not getting called. If i override the BabyClass method1() then the output is "babyclass". what is the difference. Please clarify.





Responses

Author: daya    11 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

U r not allowed to do this, it throws an exception regarding conversion;
MomClass mc = New BabyClass();


-daya



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : sql connectivity error?
Previous : Difference between dispose and gc.collect
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use