P is an abstract class, I want to make it member of class A which is a normal concrete class. Is it possible if yes how. Relationship is composition Thanks for help
No. Abstract class can have both an abstract as well as concrete methods. A concrete class can only have concrete methods. Even a single abstract method makes the class abstract.
An abstract class can extend another abstract class. And any concrete subclasses must ensure that all abstract methods are implemented. Abstract classes can themselves have concrete implementations of methods. These methods are inherited just like a method in a non-abstract class.
Yes, it is entirely possible. Being made abstract does not prevent it from extending from a concrete class. The general idea of abstract class is to provide common properties and behaviours (especially behaviours to be implemented individually in its subclass).
Since P
is abstract, you can never create an object of that type. However, you can store a pointer to P
as a member of class A
; this pointer member could then point to an instance of a (concrete) subclass of P
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With