Results 1 to 6 of 6

Thread: How does abstract function differs from virtual function?

  1. #1
    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,856

    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    1,949

    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 10:14 AM.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    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.

  5. #5
    Join Date
    May 2008
    Posts
    2,015

    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.

  6. #6
    Join Date
    May 2008
    Posts
    2,393

    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.

Similar Threads

  1. Unable to call overridden virtual function
    By Kasper in forum Software Development
    Replies: 4
    Last Post: 23-02-2010, 05:38 PM
  2. Pure virtual function call
    By Heather5 in forum Software Development
    Replies: 4
    Last Post: 21-10-2009, 10:54 PM
  3. Winword.exe R6025 - Pure Virtual Function Call
    By Dharuna in forum MS Office Support
    Replies: 2
    Last Post: 09-06-2009, 12:27 AM
  4. How to function daemon Tools as a Virtual CD Burner?
    By Faakhir in forum Windows Software
    Replies: 3
    Last Post: 25-02-2009, 07:58 PM
  5. Virtual function in c#
    By kaartik in forum Software Development
    Replies: 2
    Last Post: 10-01-2009, 11:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •