Top Answer
User Avatar
Wiki User
Answered 2012-05-11 01:31:55

An abstract class is an abstract data type (ADT). An ADT has one or more pure-virtual functions that must be implemented in derived classes or they, too, become abstract. ADTs cannot be instantiated, even if they provide implementations for their pure-virtual functions. They are intended to be derived -- they merely provide the definition of an interface for those derivatives.

A virtual class is used when a derived class uses multiple inheritance, where two or more of the base classes inherit from a common base class. Since the derived class would inherit two or more versions of the common base class, an ambiguity exists as to which common base class would be used via implicit calls in the derived class. One way around this is to use explicit calls from the derived class. But by declaring all but one of the base classes to be virtual, only one copy of the common base class will be visible to the derived class.

User Avatar

Your Answer

Related Questions

Unlike abstract class in C++, the abstract class in C# does not have any methods defined as virtual by default. The concept of virtual are not the same between C# and C++, either. Any virtual method must be defined explicitly in C#. Related to abstract methods - interestingly, an abstract class in C# does not have to have any abstract methods. However, the reverse, if a class need to have at least one abstract method, that class must be defined as abstract.

Any class that has one or more pure-virtual functions is an abstract class.

abstract class no defination used by derieved class where virtual base class is defination that can be overriden later on

In C++, an abstract data type is a class that must be derived into a child class. It is not possible to instantiate an abstract class. Another way to define this is to say that an abstract class contains pure virtual functions or that it inherits from a class with pure virtual functions but does not provide an implementation for them.

An abstract class is any class definition that contains at least one pure-virtual function. class AbstractClass { public: virtual void DoSomething()=0; // Pure-virtual. };

C is not an object-oriented programming language and therefore has no concept of abstract classes. In C++, however, an abstract class is a base class that declares one or more pure-virtual functions. An abstract base class is also known as an abstract data type (ADT). Pure-virtual functions differ from virtual functions in that virtual functions are expected to be overridden (but needn't be) while a pure-virtual function must be overridden (but needn't be implemented by the ADT). Once overridden by a derived class, the function reverts to being a virtual function with respect to further derivatives. However, only classes that provide or inherit a complete implementation of the pure-virtual interface can be instantiated in their own right; those that do not are themselves abstract data types.

I have to assume the question is for C#, not C, because C does not provide abstract class concept.public abstract class A1 { public virtual void SayHi() { Console.WriteLine("Hello World"); }public abstract void DoSomething();}The above abstract class A1 contains 1 virtual method and 1 abstract method. [Note that because of the abstract keyword for Dosomething(), A1 must be declared as abstract. An abstract class DOES NOT have to have any abstract methods!!)The virtual function SayHi() provides a implementation, while the abstract function provides nothing but only the method signature( the name of the method, the return type, and method parameters and their data types). The derived class of A1 has the option to override SayHi() and must implement (or defer to subclasses of this derived class) the method DoSomething()

abstract class is a class label with abstract. It is just like a common class, with the following characterics: 1. Abstract class cannot be instantiate with an instance. 2. Abstract class may have abstract methods, while the normal class cannot have abstract methods. a virtual function in C# is a way to provide a default implementation for the class hierarchy. Both abstract class and common class (not sealed) can have virtual methods/ functions. Note that an abstract method (of an abstract class) is defining the intent, no codes (no default behavior), the implementation are left for the derived classes to do so. The virtual function if defined in an abstract class must define the implementation, the minimum is to do nothing: public abstract class Vehicle { public abstract int GetNumberOfTires(); public virtual void Move() { // default is doing nothing} } public class Car : Vehicle { public override int GetNumberOfTires() { return 4; } public override void Move() { throws new OutOfFuelExpection(); } }

Neither Java nor C# provides a feature to define virtualclasses. Abstract classes may be defined in both languages.An abstract class is a class contains (and should) at least one abstract method (and properties in c#). The idea is to establish a service contract (the name of the method, the returning type, the arguments, etc, the method signature) but provides no implementation (no method body). The implementation is deferred on purposely to be done in the derived classes. This abstract class has no knowledge what the derived classes will actually do.Similar to abstract method, there is a virtual method in C# (in Java, every method can be a virtual method in a non-final class), it does provide one of the possibly implementation (with method body). The derived may opt to override it, inherit from that, or perform additional steps before and/or after the default implementation. A class contains at least 1 virtual method DOES NOT make that class a virtual one.

An abstract class is a class which has atleast one pure virtual function.An abstract class does not have any objects.It is used just for sharing it's members to some other classes.the class that shares the members of base class should define the pure virtual function if not object is not been created for example: class classname { protected: virtual datatype fname(parameters)=0; };

An abstract class is a class that contains at least one pure virtual function. A definition is not needed for pure virtual functions, as derived classes must override them. virtual void foo() = 0; Abstract classes cannot be instantiated. They provide a template for derived classes, and you can also point to them with pointers to utilize polymorphism. Additionally, a class derived from an abstract class must override ALL of the pure virtual functions, in order to make the class concrete. Implementing fewer than all of them will automatically make the derived class abstract, and instantiation of the derived class will not be possible.

They are not comparable, but may have some relationship between them.An abstract class is a class, while a virtual function (or method) is a method. A method must exist within a class. Hence, a class has methods, and the methods may be defined as virtual functions.A virtual function must be defined in a class, but that class does not have to be an abstract class. However, the purpose of a virtual function in C# is to provide a default behavior/implementation, while allowing the derived class to override that default implementation, hence it makes no sense to define a virtual function in a sealed class (a leaf, that is, no class can extend from it, and it is not an abstract class)Example:public class Parent {public virtual string MostCommonPhrase() {return "You better listen to me...";}}public class Child : Parent {public override string MostCommonPhrase() {return "You never listen to me...";}}

An abstract data type is any class or struct that contains at least one pure virtual function.

Yes an abstract class can inherit from another abstract class but all the methods of the base abstract class must be abstract.

A generic class is a class that contains one or more virtual methods and is intended to act as a base class for more specific, specialised classes, known as derivatives or derived classes. A generic class that has one or more pure virtual methods is also known as an abstract base class or abstract data type.

A pure-virtual method is similar to a virtual method. A virtual method is a method that is expected to be overridden in a derived class while a pure-virtual method must be overridden in a derived class. The base class may provide a default implementation for a pure-virtual method, but it is not a requirement, whereas it must provide an implementation for a virtual method. In addition,any base class that has a pure-virtual method becomes abstract; you cannot instantiate abstract classes -- you are expectedto derive from them.#include class Abstract{public:// Pure-virtual method; note the '=0' to denote pure-virtual.virtual void Show()=0;};class Derived : public Abstract{public:virtual void Show(){// Implementation is required here!std:: cout }};void main(){// Abstract a; // Compiler error!Derived d;d.Show(); // Call pure-virtual method.return( 0 );}

In C++, a pure virtual function is a function declaration that has no implementation in the class where it is declared, but is rather left to the child classes to override and define the function. This means that the parent class cannot be instantiated. In Java this is known as an abstract class or interface.

To ensure the base class cannot be instantiated. Any class with a pure-virtual function becomes abstract; you are expectedto derive new classes from an abstract class and you mustprovide an implementation for the pure-virtual method, either in the derived class itself or in one of its derivatives. A derived class that does not implement a pure-virtual function inherited from its base class becomes abstract itself. Derived classes may also declare their own pure-virtual methods, which also renders them abstract.Abstract classes merely provide the basis upon which to create fully-implemented classes. The least-derived class is the least-specialised. As classes becomes more derived, they become more specialised. When a specialised class fully implements all the pure-virtual functions below it (either through inheritance or by providing the implementation itself), that class can finally be instantiated as an object.Note that although the class that declares a pure-virtual function can also provide an implementation for it, the derived class (or one of its derivatives) must override that implementation. Default pure-virtual implementations cannot be inherited by derived classes, but the overrides can call them, just as they can with non-pure virtual functions.

An abstract class is a class that has a pure virtual function. A pure virtual function can be used in a base class if the function that is virtualised contains parameters that can and should be interchangeable, but the function should remain intact. For example, there is a base class Object in a game that will contain movement for simple objects, but the movement function may need to use different parameters per object.

A virtual function is a base class method that is expected to be overridden by derivatives (derived classes) of the base class, thus providing runtime polymorphic behaviour whenever calling the base class method. That is, the most-derived class method is actually executed. By contrast, a non-virtual method may still be overridden but it will not exhibit runtime polymorphic behaviour. In addition, a pure-virtual function is an abstract base class method that must be overridden by a derivative, otherwise the derivative is also rendered abstract.

An abstract class is an abstract data type (ADT). They are used to describe a common interface to the objects that derive from them. You cannot instantiate objects from abstract classes, they must be derived from. Only derivatives that fully implement all the virtual methods they inherit from their ADTs can actually be instantiatedA virtual class is used in multiple inheritance cases where a derived class inherits from two or more base classes that each inherit from a common base class. The common base class must be declared virtual in all its derivatives to ensure only one instance of the common base class is present in any classes that inherit from two or more of the derived classes. Without virtual inheritance, the most-derived class would have multiple instances of the common base class, which introduces an undesirable ambiguity to the class.For instance, if you declare an animal ADT from which winged_animal and mammal are both derived, a bat class would inherit two animal ADTs as it is both a mammal and a winged_animal. To avoid this, animal needs to be declared a virtual inherited class in both mammal and winged_animal. Now bat will inherit only one animal ADT and the ambiguity is completely removed.

Virtual functions are not used in C, but in C++.In C++, we use virtual functions to ensure the correct function is called at runtime. If a derived class overrides a function from its base class, the base class' function will still be called unless it is a virtual function. The usual goal is to call the derived class' function, so all functions that are designed to be overridden should be declared as virtual.

A concrete class is a complete type, as opposed to an abstract class which is an incomplete type.class A {public:virtual void f () = 0; // pure-virtual; class A is abstract// ...};class B : public A {public:void f () override; // overrides A::f(); class B is concrete};class C {// no pure-virtual methods; C is a concrete type// ...};Template classes are generic types. We usually evolve a generic type from a concrete type rather than write a template class from scratch, a technique known as lifting. The concrete type provides us with the complete implementation which is useful for testing and debugging purposes. When the concrete class is fully-implemented and error-free, we can generalise to produce the generic type.

When we declare a pure virtual member function, the class in which it is declared becomes an ADT (abstract data type). The base class that declared the pure-virtual function need not provide an implementation for it. Unlike a virtual function which maybe overridden by a derived class, a pure-virtual function must be overridden by a derived class, otherwise it, too, becomes an ADT. However, once overridden, a pure-virtual function becomes a normal virtual function with respect to further derivatives.

It has various meanings depending on the context. A virtual method in a base class implies the method may be overridden by a derived class, in which case calling that method on the base class calls the method in the most-derived class that implements that method. This is achieved via the virtual table (v-table), so there is no need to determine the actual type of the derived class at runtime. A pure-virtual method in a base class implies the class is abstract and must be derived from, and that a derivative must implement the method (or it becomes abstract itself). You cannot instantiate abstract classes. They are intended purely to provide a common interface to their derivatives. A virtual base class is a class that is common to two or more derived classes that may be combined in a multiple-inheritance class. If the derived classes declare the base class virtual, the derived classes will share the same instance of the base class, and the multiple-inheritance class will inherit just one instance of the base class from those derived classes. If the derived classes do not declare the base class virtual, the derived classes have separate instances of the base class, which inevitably leads to an ambiguity in the multiple-inheritance class.

Copyright ยฉ 2021 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.