Ok, my brain is totally frazzled over this, partly because the courses system has a bug in it, and I came to completely the wrong conclusions then trying to understand inheritence...
So i'm hoping someone here can clear things up for me.
If I had a class ClassA & a sub-class of ClassA, called ClassB.
I understand that you can perfom the following...
However the object instance referenced by myclass, although initialised as a ClassB object it is actually only a ClassA object and only instance attributes and methods from ClassA will be permitted / accesible. (in the course IDE, you can run methods of ClassB after creating the object as above, which apparently is wrong.) Hence my total confusion over all this.
So is the only reason a declared variable allows this is so you can use Polymorphism in your code and that is how polymorphic methods are exacutable, by allowing a required variable type to be passed as an argument, that is declared as either the required class or any super-class declared variable.
Which also helps in the creation and use of abstract classes for method sharing (polymorphic methods).
Is that right?
Thanks,
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Google Rank Extractor -> PERL v1.5 beta (FusionCharts)
So i'm hoping someone here can clear things up for me.
If I had a class ClassA & a sub-class of ClassA, called ClassB.
I understand that you can perfom the following...
Code:
ClassA myclass = new ClassB();
However the object instance referenced by myclass, although initialised as a ClassB object it is actually only a ClassA object and only instance attributes and methods from ClassA will be permitted / accesible. (in the course IDE, you can run methods of ClassB after creating the object as above, which apparently is wrong.) Hence my total confusion over all this.
So is the only reason a declared variable allows this is so you can use Polymorphism in your code and that is how polymorphic methods are exacutable, by allowing a required variable type to be passed as an argument, that is declared as either the required class or any super-class declared variable.
Which also helps in the creation and use of abstract classes for method sharing (polymorphic methods).
Is that right?
Thanks,
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Google Rank Extractor -> PERL v1.5 beta (FusionCharts)