x

Choose Country Code

x

Direction

x

Ask a Question

  • Ask a Question
  • Scan a Question
  • Post MCQ
  • Note: File extension must be of jpg, jpeg, png, bmp format and file size must not exceed 5 MB
x

Ask a Question

x

x
x
x
Hire a Tutor

Answers and Solutions

What's Your Question?
Answer

An abstract class is one, which is never instantiated.  The objects of an abstract base class are never created.  A base class that contains pure virtual functions is an abstract base class.  A pure virtual function is a virtual function that has no implementation in.

A virtual class is one that has been qualified as virtual in the inheritance definition.  When a derived class inherits from more than one base class, then it can inherits the members of a base class from multiple inheritance pathsits class

Answer
Sometimes implementation of all function cannot be provided in a base class because we don’t know the implementation. Such a class is called abstract class. For example, let Shape be a base class. We cannot provide implementation of function draw() in Shape, but we know every derived class must have implementation of draw().We cannot create objects of abstract classes. So an abstract is a class with atleast one pure virtual function. Pure virtual function is a virtual function which has no implementation and is implemented by the services classes. Pure virtual function is declared to zero.
Answer

 

 

 

Virtual class-

i)When a derived class inherits from more than one base class, then it can inherits the members of base class from muliple inheritance paths.

ii) If base class defined by virtual,only one copy of the member of base class inherit derived class.

Abstract class-

i) It is not instantiated.

ii) Objects of abstract base class never created.

iii) Base class contains pure virtual functions is abstract base class.

 

Answer
An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function in the class declaration. Virtual base classes, used in virtual inheritance, is a way of preventing multiple "instances" of a given class appearing in an inheritance hierarchy when using multiple inheritance.
Answer
Abstract class is a class having at leat one virtual function. Abstract class having pure virtual function cant be instantiated. Abstract class badically provide a generic framework to implement any specific sub class having same member with modification may be. Virtual function is used to invoke function of derived class when the base pointer points to derive class member function. Compiler creates a hidden vpointer table for the class having virtual function..it is assigned the address of other class function
Answer

An abstract class is one, which is never instantiated.  The objects of an abstract base class are never created.  A base class that contains pure virtual functions is an abstract base class.  A pure virtual function is a virtual function that has no implementation in.

A virtual class is one that has been qualified as virtual in the inheritance definition.  When a derived class inherits from more than one base class, then it can inherits the members of a base class from multiple inheritance pathsits class

 

Answer

An abstract class is, conceptually, a class that cannot be instantiated and is usually implemented as a class that has one or more pure virtual (abstract) functions.

Suppose you have two derived classes B and C that have a common base class A, and you also have another class D that inherits from B and C. You can declare the base class A as virtual to ensure that B and C share the same subobject of A.

 

Answer

Abstract class contain at least one pure virtual function and virtual class is nested inner class whose function and member variables can be overridden.

Answer

Abstract Class is a class which contains atleast one Pure Virtual function in it. Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the pure virtual function, otherwise they will also become abstract class.

In object-oriented programming, a virtual class is a nested inner class whose functions and member variables can be overridden and redefined by subclasses of the outer class.

Answer

Abstract Class

Abstract Class is a class which contains atleast one Pure Virtual function in it. Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the pure virtual function, otherwise they will also become abstract class.

Characteristics of Abstract Class

Abstract class cannot be instantiated, but pointers and refrences of Abstract class type can be created. Abstract class can have normal functions and variables along with a pure virtual function. Abstract classes are mainly used for Upcasting, so that its derived classes can use its interface. Classes inheriting an Abstract Class must implement all pure virtual functions, or else they will become Abstract too.

Pure Virtual Functions

Pure virtual Functions are virtual functions with no definition. They start with virtual keyword and ends with= 0. Here is the syntax for a pure virtual function,

virtual void f() = 0;

Example of Abstract Class

class Base //Abstract base class { public: virtual void show() = 0; //Pure Virtual Function }; class Derived:public Base { public: void show() { cout << "Implementation of Virtual Function in Derived class"; } }; int main() { Base obj; //Compile Time Error Base *b; Derived d; b = &d; b->show(); }

Output : Implementation of Virtual Function in Derived class

In the above example Base class is abstract, with pure virtual show() function, hence we cannot create object of base class.

Why can't we create Object of Abstract Class ?

When we create a pure virtual function in Abstract class, we reserve a slot for a function in the VTABLE(studied in last topic), but doesn't put any address in that slot. Hence the VTABLE will be incomplete.

As the VTABLE for Abstract class is incomplete, hence the compiler will not let the creation of object for such class and will display an errror message whenever you try to do so.

Pure Virtual definitions

  • Pure Virtual functions can be given a small definition in the Abstract class, which you want all the derived classes to have. Still you cannot create object of Abstract class.
  • Also, the Pure Virtual function must be defined outside the class definition. If you will define it inside the class definition, complier will give an error. Inline pure virtual definition is Illegal.

class Base //Abstract base class { public: virtual void show() = 0; //Pure Virtual Function }; void Base :: show() //Pure Virtual definition { cout << "Pure Virtual definition\n"; } class Derived:public Base { public: void show() { cout << "Implementation of Virtual Function in Derived class"; } }; int main() { Base *b; Derived d; b = &d; b->show(); }

Output : Pure Virtual definition Implementation of Virtual Function in Derived class

Answer

Abstract class is a class which has atleast one abstract method in it as its member. Now Abstract methods are those methods which have no written definition in them. If we inherit the abstract class, then we need to override all its abstract methods as well, otherwise the new class will also become Abstract.

Answer
  • An Abstract class is one, that is not used to create object. It is designed to only to act as 'base class'(interface).
  • But we can create pointers & references for an Abstract class.
  • And and as Nagamanjula said, It MUST have atleast one pure virtual funtion & all derived classes of it MUST define that virtual funtion.
  • Virtual class is nothing but Virtual Base class. When any class is inherited through multiple paths then there exists an ambiguity. We use this VBC to avoid this ambiguity. ex: class Base       classs D1 : public Base       class D2 : public Base       class DOD : public D1, public D2. //ambiguity.   To avoid we have to .....       classs D1 : virtual public Base       class D2 :  virtual public Base  
Answer

Abstract Class is a class which contains atleast one Pure Virtual function in it. Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the pure virtual function, otherwise they will also become abstract class.

 a virtual class is a nested inner class whose functions and member variables can be overridden and redefined by subclasses of the outer class.[1] Virtual classes are analogous to virtual functions.

Post Answer and Earn Credit Points

Get 5 credit points for each correct answer. The best one gets 25 in all.

Post Answer