Question:
difference b/w virtual class and abstract class???
Asker
2008-06-15 10:16:09 UTC
wat s virtual class and wat s abstract class
Three answers:
JoelKatz
2008-06-15 10:30:58 UTC
An abstract class is a class that has no data members and no function implementation. An abstract class just contains a list of function prototypes. They're used to specify just an interface without any implementation.



For example, you might have an abstract class called a 'list'. It might contain functions to add something to the list, functions to remove something from the list, and functions to go through the list and see what's on it. But it contains no information whatsoever about *how* those functions should work or how the list should be stored.



This would allow you to make one implementation that's singly-linked, another implementation that's doubly linked, and another that works a completely different way if you want. Other functions could call the interface functions to visit every element in a list no matter what kind of list it actually was.



As for a 'virtual class', I have never heard of such a thing. Sometimes an abstract class is called a "pure virtual class".



There is also a "virtual base class". A "virtual base class" is a base class that would appear twice in the inheritance tree but is "folded" to appear only once. For example, suppose you have a base class of "Musician", derived from "Person". Derived from "Musician", you have "Violinist" and "Guitarist". If you had a Person who was both a Violinist and a Guitarist, they'd normally have two instances of Person (since a Violinist is a person and a Guitarist is a Person). That's clearly not right, since they're only a single Person (and therefore should only have one of anything a Person has, such as a Name, Birthdate, and so on). By making Person a virtual base class, there will only be one 'Person', rather than one for each base class that derives from 'Person'.
Bizzil Hizzause
2008-06-15 10:28:06 UTC
An abstract class is a class that has one or more virtual functions that must be overridden by derived classes.



Normally virtual refers to functions or methods and not classes but there is such a thing as a virtual class.



A virtual class is a class that is used to avoid ambiguity when using multiple inheritance (See the following link for more)

http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr135.htm



Hope that helps
lowrey
2016-10-17 16:35:50 UTC
in fairly much each and every merchandise orientated language (which includes Java), an precis type ability a type that may no longer very useful in case you have an occasion of it, yet in basic terms used for subclassing. So precis training are extra like templates, whilst non precis training are merely well-known training.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...