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  

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

Imagine a protein that functions in the ER but requires modification in the Golgi apparatus before it can achieve that function. Describe the protein’s path through the cell, starting with the mRNA molecule that specifies the protein.
The protein is synthesized into the lumen of the ER and perhaps modified there. A transport vesicle carries the protein to the Golgi apparatus. After further modification in the Golgi, another transport vesicle carries it back to the ER.
Mano
2 0
6
What is acromegaly ?
Hyper pituitary secretion for growth hormone during adulthood.
Kumar Upendra Akshay
How to get scholarship in Japan?
Along with Japan embassy web, Indo-Japan bilateral programs can give you more insight.
Mohammed
What is the difference between horizontal and vertical ellipse?
If the larger number is under x, then it is a horizontal ellipse. If it is under the y then it is vertical.
Ramala

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

Ask a Question

Related Lessons

How To Learn Theory Subjects
How To Learn Theory Subjects Without marking, correlation, set views in mind & revise you can’t remember any subjects which are theoretical or have numerical formulas..... First select...

Introduction To Accounting: Part 4: Accounting Cycle
Remember when we started learning English? We started off by learning Alphabets, then we joined Alphabets to form Words, then we joined Words to form Sentences, then we joined Sentences to form Paragraphs,...

Dissolution Of Partnership Firm - Questions
CHAPTER: 5 Q.1 Distinguish between dissolution of partnership and dissolution of partnership firm on the basis of continuation of business. Q.2 Why is Realisation Account prepared on dissolution of partnership...

How To Score 90+ in Accountancy Class XII
Hi friends, I am witnessed with the few facts that how your performance gets improved by following activities. 1. Learn all the concepts focus upon learning and applying the concept rather than focusing...

CELL- The basic unit of life
The smallest structural and functional unit of an organism, which is typically microscopic and consists of cytoplasm and a nucleus enclosed in a membrane. The concept of cell originated from the...

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