I’m learning java and have a question about object types.
Take the following as an example:
class A { }
class B extends A { }
class C {A myObject = new B();}
What is the accepted way to describe the type of myObject?
Would you say it is Type A, Type B, or Type A and B?
Thanks.
myObjectis a reference of typeA(your variable is declared to be of typeA).The object itself, which is referred to by
myObject, is of typeB. The instance is of typeB.It’s a matter of context and focus.
When you use
myObjectin other places you may not know it is an instance of classB, only that it is of typeA.