TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
maheswar reddy
NA
27
46.5k
What is the use of virtual and override?
Sep 30 2011 2:49 AM
Hi Everyone,
I had tried the following programs.
1 st program---------------------------
public class a
{
public void run()
{
console.writeline("hai");
}
}
public class b:a
{
public void run()
{
console.writeline("hello");
}
class c
{
public static void main()
{
b b1 =new b();
b1.run();
a a1=new a();
a1.run();
}
}
2 ND program----------------
public class a
{
public vitual void run()
{
console.writeline("hai");
}
}
public class b:a
{
public override void run()
{
console.writeline("hello");
}
class c
{
public static void main()
{
b b1 =new b();
b1.run();
a a1=new a();
a1.run();
}
}
note:
These two programs print same output means for which i had created object for class ,that method will be called.Then what is the role of Virtual and Override.We already know that override is used it code replacement,but what is the another use in above program...
Thanks,
Maheswar
Reply
Answers (
1
)
Error while searching data from database
Why the static class cannot be inherited?