UrbanPro

Take Class 12 Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

What is virtual class in oops?

Asked by Last Modified  

9 Answers

Follow 0
Answer

Please enter your answer

Banker

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. Virtual classes are analogous to virtual functions. Virtual classes solve the extensibility problem of extending data abstraction...
read more
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. Virtual classes are analogous to virtual functions. Virtual classes solve the extensibility problem of extending data abstraction with new functions and representations. Like virtual functions, virtual classes follow the same rules of definition, overriding, and reference. When a derived class inherits from a base class, it must define or override the virtual inner classes it inherited from the base class. An object of the child class may be referred to by a reference or pointer of the parent class type or the child class type. When the reference or pointer invoke the virtual inner classes, the derived class's implementation will be called if the object is of the derived class type. The type of the outer class determines the run time of the inner virtual class. A method with an object argument has access to the object's virtual classes. The method can use the virtual classes of its arguments to create instances and declare variables. Virtual classes of different instances are not compatible. For example, a base class Machine could have a virtual class Parts. Subclass Car would implement Parts differently than the subclass Bicycle, but the programmer can call any methods in the virtual inner class Parts on any class Machine object, and get the Parts implementation of that specific derived class. class Machine { void run () {} virtual class Parts { }; }; // The inner class "Parts" of the class "Machine" may return the number of wheels the machine has. class Car: public Machine { void run() { cout << "The car is running." << endl; } class Parts { int get_Wheels () { cout << "A car has 4 wheels." << endl; return 4; } string get_Fuel_Type () { cout << "A car uses gasoline for fuel." << endl; return "gasoline"; } }; }; read less
Comments

C++ supports multiple inheritance. Suppose a class is inherited by two classes which in turn are inherited by a single class. If this last child wants to access a data member of its grandparent there would be ambiguity as there would be two copies of that grandparent in the memory. To solve this problem...
read more
C++ supports multiple inheritance. Suppose a class is inherited by two classes which in turn are inherited by a single class. If this last child wants to access a data member of its grandparent there would be ambiguity as there would be two copies of that grandparent in the memory. To solve this problem we use virtual base class concept. A virtual keyword instructs compiler to have only one instance of the class. So now there would be no ambiguity. read less
Comments

C++ supports multiple inheritance. Suppose there is a class which is inherited by two classes which inturn are inherited by a single class. Now if this last child wants to access data member of its grandparent there would be ambuigity. As there would be two copies of instances of the grandparent. To...
read more
C++ supports multiple inheritance. Suppose there is a class which is inherited by two classes which inturn are inherited by a single class. Now if this last child wants to access data member of its grandparent there would be ambuigity. As there would be two copies of instances of the grandparent. To solve this problem virtual base class concept is used. A virtual keyword instructs compiler to have only one instance of the class. There would be no ambiguity now. read less
Comments

Computer Science Faculty

virtual class is an imaginary class in oops.
Comments

A virtual class is an inner class that can be overridden by derived classes of the outer class.
Comments

Will Train the students as per their requirement.

A virtual class is the one that prevents multiple copies of a single base class
Comments

TRAINER FOR SOFTWARE COURSES & B.TECH TUTIONS

When two or more objects are derived from a common base class, we can prevent multiple copies of the base class being present in an object derived from those objects by declaring the base class as virtual when it is being inherited. Such a base class is known as virtual base class
Comments

Teacher

In object-oriented programming, a virtual class is a nested inner class whose functions and member variables can be overridden and redefined by sub-classes of the outer class. Virtual classes solve the extensible problem of extending data abstraction with new functions and representations.
Comments

Virtual class is used in C++ multiple inheritance. suppose: we have a base class base1. Two classes derived1 and derived2 derive from base1. A third class derived3 derives from both derived1 and derived2. base1 has a protected variable bvar. A class derived3 method accesses this variable. Now there...
read more
Virtual class is used in C++ multiple inheritance. suppose: we have a base class base1. Two classes derived1 and derived2 derive from base1. A third class derived3 derives from both derived1 and derived2. base1 has a protected variable bvar. A class derived3 method accesses this variable. Now there are two copies of bvar available for C to use -- derived1::bvar and derived2::bvar. So the compiler gives error for ambiguity. If, however, classes derived1 and derived2 declare base1 as virtual base class this problem would be avoided. When a base class is declared as virtual only one copy of its data members exist in memory. At runtime it will be checked whether an object of the base class base1 is created in memory, if not it will be created, if yes the same copy will be referred. So there will be no ambiguity. read less
Comments

View 7 more Answers

Related Questions

What is the tution fee for 1st PUC Mathematics,Physics and Computer science  per hou?

Well, Komal it depends on the Location if you are within 5-6 km from my location then the fee will be for Mathematics (500/hr), Physics(600/hr) and if your location is more than that then the charges will...
Komala Nataraj
How Can I have a good job of teaching.
most of this providers are not free, so upgrade your account, start contacting your students
Anwer
I also want to teach 4 my hobby but not for making money ? Is there anyone who need for any tution but can not afford such heavy fee? I am ready to teach you without any fee. Those who are in need, please feel free to contact me.
Wonderful idea but I have experience of free coaching and students who do not pay are much less serious than who pay. The reason is simple free goods do not have value! free students are more apt to miss...
Manish

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Class 12 Organic Chemistry - Assigning R And S Configurations.
Configuration is the relative position of the atoms in amolecule that can be arranged / changed exclusively by cleaving and forming new chemical bonds. Steps to assign configurations: Follow the direction...

Chemistry
What is pKa value of a weak acid? How is it related to its pH? Explain. PH depends on the concentration of the solution. This is important because it means a weak acid could actually have a lower...


Biology Question and Answer
Which protein(s) make up a skeletal muscle thick filament? Question options: 1) Troponin 2) Actin 3)...
S

Subimal Banerjee

1 0
0

feed your brain to improve concentration
1. never try to study when you are pysicslly weak.if your brain is not fresh enough you cannot concentrate. 2. drink lots of water to keep your brain fresh. 3. just before every learning session drink one glass of water

Recommended Articles

Looking for Class 12 Tuition ?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Class 12 Tuition Classes?

The best tutors for Class 12 Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take Class 12 Tuition with the Best Tutors

The best Tutors for Class 12 Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more