Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How does abstract function differs from virtual function?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 29-01-2010
Member
 
Join Date: Dec 2009
Posts: 18
How does abstract function differs from virtual function?
  

I am beginner programmer in the programming world. I am learning the programming C++, C sharp, Java, .NET and DBMS. Now a days, i am working on the Java and C sharp language. I want to know how does abstract function differs from virtual function, in which case it is better to use abstract or virtual function? Please help me.

Reply With Quote
  #2  
Old 29-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,845
Re: How does abstract function differs from virtual function?

According to me, the virtual function doesn't work on classes. They are only meant for a class method, properties, indexer or event declaration to have the possibility, and to override them in the derived class. And on the other side, the abstract class cannot be initiated and can more interpreted as a template of a class, which has to be derived to make an instance of it. Important to note that any class with abstract method or property in it should be declared as abstract. Hope your problem will be fix.
Reply With Quote
  #3  
Old 29-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: How does abstract function differs from virtual function?

I think that virtual method/function contains only the implementation and it provide the derived class with the option/way of overriding it. Whereas the abstract method doesn't provide/contain an type implementation and it forces the derived class to override the method. An abstract class may contain abstract methods and accessors. Also note that trying to instantiate an object of an abstract class results in a compile error. Hope you will understand the term virtual and abstract.

Last edited by Praetor : 29-01-2010 at 11:14 AM.
Reply With Quote
  #4  
Old 29-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: How does abstract function differs from virtual function?

Abstract method/function: A class which will have the abstract methods/functions, then that class should be declared as abstract. The abstract method/function does not have implementation and thus, classes that derive from that abstract class, must provide an implementation for this abstract method.
Virtual method: Any class can contain the virtual method/function. The virtual does not work on classes. This virtual method/function comes with an implementation. And as you inherit from a class which has a virtual method, you can override the virtual method and provide additional logic, or replace the logic with your own implementation.
Reply With Quote
  #5  
Old 29-01-2010
Member
 
Join Date: May 2008
Posts: 2,007
Re: How does abstract function differs from virtual function?

I think this two keywords(i.e virtual and abstract) are many confusing because both of them can be overridden. But abstract members does not have implementation, whereas virtual members have. The Abstract keyword can be given to either members or the class as a whole. Also note that, if a class contains the abstract member, then that class should be itself the abstract, in this not required in virtual case. This are the only difference which i know, hope your problem is fixed.
Reply With Quote
  #6  
Old 29-01-2010
Member
 
Join Date: May 2008
Posts: 2,383
Re: How does abstract function differs from virtual function?

My knowledge about the programming world says that abstract methods/functions are always consider as virtual. And they do not have any implementation. This is only the main difference between them. Usually, we will use the virtual method/function if we have a ''default'' implementation of it and want to allow descendants to change its behavior. And with abstract method we will force descendants to give the implementation. Hope your problem will be solved.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How does abstract function differs from virtual function?"
Thread Thread Starter Forum Replies Last Post
Unable to call overridden virtual function Kasper Software Development 4 23-02-2010 06:38 PM
Pure virtual function call Heather5 Software Development 4 21-10-2009 11:54 PM
Winword.exe R6025 - Pure Virtual Function Call Dharuna MS Office Support 2 09-06-2009 01:27 AM
How to function daemon Tools as a Virtual CD Burner? Faakhir Windows Software 3 25-02-2009 08:58 PM
Virtual function in c# kaartik Software Development 2 10-01-2009 12:10 PM


All times are GMT +5.5. The time now is 05:50 AM.