about methods
-
what is virtual method,dynamic method,static method
-
what is virtual method,dynamic method,static method
What is homework ? What is google ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
what is virtual method,dynamic method,static method
Virtual methods are those methods which you want to call using base class object with derived class reference.
namespace SomeCorpProject
{
public class BaseBusinessObject
{
public BaseBusinessObject()
{
}public virtual void VirtualMethod() { Console.WriteLine("Virtual method"); } public override string ToString() { return "BaseBusinessObject"; } }
}
namespace SomeCorpProject
{
public class Capacitor : BaseBusinessObject
{
public Capacitor()
{
}public static void StaticMethod() { Console.WriteLine("I am static, no need to create object of class."); } public override void VirtualMethod() { Console.WriteLine("In derived virtual method"); base.VirtualMethod(); } public override string ToString() { return "Capacitor"; } }
}
namespace SomeCorpProject
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
BaseBusinessObject bizObj = new Capacitor();
bizObj.VirtualMethod();
Capacitor.StaticMethod();
System.Console.WriteLine(bizObj.ToString());
}
}
}The above code will explain most of the concepts. Static methods are those methods for which object of the class need not to be created. They share the common info across all class objects. They are loaded in the memory before class gets loaded. Dynamic methods? I do not have idea. But I think they might be instance methods. i.e. you should create an object of the class to call these methods. :)
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
-
what is virtual method,dynamic method,static method
Just adding a little, virtual methods can be overwritten in a derived class (by using overwrite keyword) but is not mandatory. Also you can have a method with the same name as the one in a parent class and hide it with a technique called shadowing (by using new keyword).
-
Virtual methods are those methods which you want to call using base class object with derived class reference.
namespace SomeCorpProject
{
public class BaseBusinessObject
{
public BaseBusinessObject()
{
}public virtual void VirtualMethod() { Console.WriteLine("Virtual method"); } public override string ToString() { return "BaseBusinessObject"; } }
}
namespace SomeCorpProject
{
public class Capacitor : BaseBusinessObject
{
public Capacitor()
{
}public static void StaticMethod() { Console.WriteLine("I am static, no need to create object of class."); } public override void VirtualMethod() { Console.WriteLine("In derived virtual method"); base.VirtualMethod(); } public override string ToString() { return "Capacitor"; } }
}
namespace SomeCorpProject
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
BaseBusinessObject bizObj = new Capacitor();
bizObj.VirtualMethod();
Capacitor.StaticMethod();
System.Console.WriteLine(bizObj.ToString());
}
}
}The above code will explain most of the concepts. Static methods are those methods for which object of the class need not to be created. They share the common info across all class objects. They are loaded in the memory before class gets loaded. Dynamic methods? I do not have idea. But I think they might be instance methods. i.e. you should create an object of the class to call these methods. :)
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
jdkulkarni wrote:
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
Wow - is that worth something in parts of the world ? I wouldn't have given the answer, because all you're doing is teaching this person to not do their own homework. I hope he ends up working in the cubicle next to you and not near me.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
what is virtual method,dynamic method,static method
Have you heard of MSDN ?? Regards, Bhupi Bhai.
-
jdkulkarni wrote:
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
Wow - is that worth something in parts of the world ? I wouldn't have given the answer, because all you're doing is teaching this person to not do their own homework. I hope he ends up working in the cubicle next to you and not near me.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
jdkulkarni wrote:
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
Wow - is that worth something in parts of the world ? I wouldn't have given the answer, because all you're doing is teaching this person to not do their own homework. I hope he ends up working in the cubicle next to you and not near me.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog