UrbanPro

Take Class 12 Tuition from the Best Tutors

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

Search in

What is virtual class in oops?

Asked by Last Modified  

9 Answers

Learn Class XI-XII Tuition (PUC)

Follow 0
Answer

Please enter your answer

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

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

View 7 more Answers

Related Questions

I don't have taken maths in 11 but have taken in 12 so how can I do it?
in order to move forward there are some thing which are very important and that can be only understood in class 11th. Now the practical step is that you have to study two classes simultaneously which is...
Nitesh
Is it possible for me to solve chemistry problems easily, if I take regular tuition for Chemistry?
You can solve Chemistry problems only if your concepts are clear
Shantham
0 0
5
What are Boolean expressions?
Boolean Expressions are logical formulation for decision making.
Vara

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

Ask a Question

Recommended Articles

Mohammad Wazid is a certified professional tutor for class 11 students. He has 6 years of teaching experience which he couples with an energetic attitude and a vision of making any subject easy for the students. Over the years he has developed skills with a capability of understanding the requirements of the students. This...

Read full article >

Radhe Shyam is a highly skilled accounts and finance trainer with 8 years of experience in teaching. Accounting is challenging for many students and that’s where Radhe Shyam’s expertise comes into play. He helps his students not only in understanding the subject but also advises them on how to overcome the fear of accounts...

Read full article >

Swati is a renowned Hindi tutor with 7 years of experience in teaching. She conducts classes for various students ranging from class 6- class 12 and also BA students. Having pursued her education at Madras University where she did her Masters in Hindi, Swati knows her way around students. She believes that each student...

Read full article >

Urmila is a passionate teacher with over 8 years of experience in teaching. She is currently pursuing her Ph. D. She provides classes for Class 11, Class 12, MBBS and Medical tuition.  Urmila began her career in teaching long before she became a teacher. She used to provide classes for foreign national students in her college...

Read full article >

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