Hello StackOverflowers.
This is almost certainly a very basic question regarding object instantiation but in the following code sample:
List myList = new LinkedList();
Is this a form of inheritance? In other words, would one read this has LinkedList "is a" List and therefore inherits the methods defined in the List class? If so, provided a user constructed two classes of his or her own and used the same syntax as above, would the answer be the same?
Thanks all.
Caitlin
Is this a form of inheritance?
No.
would one read this has LinkedList "is a" List
Yes.
and therefore inherits the methods defined in the List class?
No. List
is an interface and therefore cannot be extended/inherited (only implemented). But LinkedList
still passes as IS-A
because it implements all the methods required by the List
interface.
If a user constructed two classes of his or her own with one being the base class and the other derived from it then yes it would be inheritance. But, the following
BaseType base = new SubType();
doesn't exactly demonstrate inheritance but polymorphism made possible by inheritance i.e. since the sub type IS-A
base type as well it can be assigned to a base type reference.
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