what is a virtual class?

Answers were Sorted based on User's Feedback



what is a virtual class?..

Answer / raj

In multiple inheritance when a class D is derived by two
base classes B and C and both base class is also inherite
by same class A then then class D will get duplicate copy
of uppper most base class A.In this case class A will
declare as virtual class

Is This Answer Correct ?    41 Yes 5 No

what is a virtual class?..

Answer / kar4you

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.

In the following example, an object of class D has two
distinct subobjects of class L, one through class B1 and
another through class B2. You can use the keyword virtual
in front of the base class specifiers in the base lists of
classes B1 and B2 to indicate that only one subobject of
type L, shared by class B1 and class B2, exists.

class L { /* ... */ }; // indirect base class
class B1 : virtual public L { /* ... */ };
class B2 : virtual public L { /* ... */ };
class D : public B1, public B2 { /* ... */ }; // valid

Is This Answer Correct ?    6 Yes 0 No

what is a virtual class?..

Answer / ramakrishna

It is used to avoid the ambiguity problem in c++ (multiple
inheritance).
when sub class inherits same members from 2 base classes.
compiler dont know which variable has assigned the value.

If u declare the class as virtual only one time is
inherited in its derived class.A copy will never get
inherited.
concept of virtual methods is different purpose.
like how we have abstract key word in java,we can acheive
method abstraction using virtual keyword before a method.

please select no if u really know this answer is wrong.
people with out having knowlede saying simple know hurts
the technical world.
Regards,
Ramakrishna Yechuri
sr corporate Trainer
yrk_in@yahoo.com

Is This Answer Correct ?    6 Yes 2 No

what is a virtual class?..

Answer / ritesh parkhi

Virtual class in a part or used to implement Runtime
polymorphism.Through it dynamically we can access a class or
method of that class.With use of Pointer to base class we
can implememt it.We try to access object of any class
without regarding their class.We are passing object address
in this base class pointer to access a particulat method of
a class at runtime.

Is This Answer Correct ?    8 Yes 5 No

what is a virtual class?..

Answer / roll no 009

it is nuthin but a class which consists of 72 students wid
a borin h.o.d who thinks all are listening but you know the
truth i.e no 1 is 4 sure..such a type of class is called
a "VIRTUAL CLASS"..

Is This Answer Correct ?    4 Yes 18 No

Post New Answer

More OOPS Interview Questions

What is an advantage of polymorphism?

0 Answers  


Name an advantage of array over linked list?

24 Answers   GML, IBM, Software Solutions,


Why multiple inheritance is not possible?

0 Answers  


What is the concept of object oriented program?

6 Answers  


What are benefits of oop?

0 Answers  






What do you mean by pure virtual functions?

8 Answers  


write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.

0 Answers   Microsoft, TCS,


Write a program to multiply 3x3 matrics

1 Answers  


How can we use the preprocessor #if and #elseif.

2 Answers  


Objective The objective of this problem is to test the understanding of Object-Oriented Programming (OOP) concepts, in particular, on encapsulation. Problem Description Create a program for managing customer’s bank accounts. A bank customer can do the following operations: 1. Create a new bank account with an initial balance. 2. Deposit money into his/her account. 3. Withdraw money from his/her account. For this operation, you need to output “Transaction successful” if the intended amount of money can be withdrawn, otherwise output “Transaction unsuccessful” and no money will be withdrawn from his/her account. Input The input contains several operations and is terminated by “0”. The operations will be “Create name amount”, “Deposit name amount”, or “Withdraw name amount”, where name is the customer’s name and amount is an integer indicating the amount of money. There will be at most 100 bank accounts and they are all created on the first month when the bank is opening. You may assume that all account holders have unique names and the names consist of only a single word. Output The output contains the transaction result of withdrawal operations and the final balance of all customers after some withdrawal and deposit operations (same order as the input). Sample Input Create Billy 2500 Create Charlie 1000 Create John 100 Withdraw Charlie 500 Deposit John 899 Withdraw Charlie 1000 0

0 Answers  


What is for loop and its syntax?

0 Answers  


What does the code "cout<<(0==0);" print? 1) 0 2) 1 3) Compiler error: Lvalue required

15 Answers   ISTS, Wipro,


Categories