C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 8)
8.
How many instances of an abstract class can be created?
Discussion:
57 comments Page 1 of 6.
Abdul Rizwan said:
1 decade ago
@Bhavik.
Abstract class is used to reduce the complexity of method overriding or data hiding.
As we know abstract method don't have definition part, so for define the abstract method we must have to inherit the abstract class with some other base class.
And suppose we are able to create an object of an abstract class and we are calling the abstract method using object then in that abstract method don't have code so compiler will stuck and your program will hang over there.
So to reduce the problem or programmer don't make any mistake, Developer has put the restriction to create an object of an abstract class.
Instead of object we can create a reference variable of abstract class. Using ref variable also we can call abstract method but before calling we need to pass an object of base class to a ref variable.
Abstract class is used to reduce the complexity of method overriding or data hiding.
As we know abstract method don't have definition part, so for define the abstract method we must have to inherit the abstract class with some other base class.
And suppose we are able to create an object of an abstract class and we are calling the abstract method using object then in that abstract method don't have code so compiler will stuck and your program will hang over there.
So to reduce the problem or programmer don't make any mistake, Developer has put the restriction to create an object of an abstract class.
Instead of object we can create a reference variable of abstract class. Using ref variable also we can call abstract method but before calling we need to pass an object of base class to a ref variable.
K2u2007 said:
1 decade ago
A class that contains at least one pure virtual function is said to be abstract. Because an abstract class contains one or more functions for which there is no definition (that is, a pure virtual function), no objects of an abstract class may be created.
Instead, an abstract class constitutes an incomplete type that is used as a foundation for derived classes. Although you cannot create objects of an abstract class, you can create pointers.
And references to an abstract class. This allows abstract classes to support run-time. polymorphism, which relies upon base-class pointers and references to select the proper virtual function.
Instead, an abstract class constitutes an incomplete type that is used as a foundation for derived classes. Although you cannot create objects of an abstract class, you can create pointers.
And references to an abstract class. This allows abstract classes to support run-time. polymorphism, which relies upon base-class pointers and references to select the proper virtual function.
Abhishek singh said:
9 years ago
Abstract Class: A class is called as abstract class if it must have one or more abstract method.
Abstract method: Method which we just declare but not define, every class which inherits abstract class containing abstract method must define that method in its own way.
Abstract class can't have an instance object or variable because if we create an object of abstract class and using that object if we try to access abstract method then we will get compile time error as we don't have anything inside abstract method of that abstract class.
Abstract method: Method which we just declare but not define, every class which inherits abstract class containing abstract method must define that method in its own way.
Abstract class can't have an instance object or variable because if we create an object of abstract class and using that object if we try to access abstract method then we will get compile time error as we don't have anything inside abstract method of that abstract class.
(1)
Prashant said:
9 years ago
So let's say we have a team creating a big project and we want the whole team to create many classes but they all must inherit a single BASE class for some particular functionality like debugging. So if we would create an abstract class which has only one virtual function which gives a debugging interface and inherits this is in all the other team's classes it would be easier. Why virtual because the derived classes could also have the same function with the same signature.
(5)
Suraja said:
1 decade ago
Memory Allocation to the class members is done when its object is created. For an abstract class, memory cannot be allocated as its resource requirement cannot be calculated. Hence no object for an abstract class.
Akshat Sharda said:
1 decade ago
Object of only those class are created in which all the functions are declared. As we know that in abstract class we only declare the functions, the definition of function are given by inherited class.
Pooja said:
1 decade ago
In abstract class object can't be created. Abstract classes cannot be used for:
1) Variables or member data.
2) Argument types.
3) Function return types.
4) Types of explicit conversions.
1) Variables or member data.
2) Argument types.
3) Function return types.
4) Types of explicit conversions.
Nikita choudhary said:
1 decade ago
No objects an be created for abstract class, besides abstract class is not defined class. Its practically similar to the noun abstract which cannot create any members within it.
Aakash Gupta said:
1 decade ago
Talking in terms of java, an abstract class can have any number of instances but can't have any object. But since this question. Is listed in oops concept, option d is correct.
Mohammed said:
1 decade ago
Abstract base class may be used only as framework from which other class will be derived, while the individual objects of this class will never be instantiated.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers