I think you are using the wrong names. If you look in the Java® Language Specification (=JLS), you will find out that the opposite of reference type is primitive type.
I think you meant to say declared type and runtime type.Here the declared type and runtime type are both the same: Car. I am not sure I would have a class Meredes, but you might have a class like this:-Now you can sayor even one suitable for after boozy Christmas parties In all those cases, the declared type is Car, but the runtime type might be a Taxi; The last code snippet doesn't allow anybody to decide what type it is until runtime.
The javac tool tests the declared type of all references, and ensures that all objects assigned thereto are of that type (that type includes subtypes). So you can assign a Car or a Taxi to a reference declared Car. You can assign a Square, Rectangle or Rhombus to a Shape declared type. That means only methods declared in the types Car/Shape can be used. You cannot therefore writebecause there is no such method in the Car class. You can however cast the Car reference, and that will make me pay the £13.50, but I shall leave you to work out what might go wrong with this sort of code:-Look at line 23 in the code you posted.
I shall also let you work out why I have used the BigDecimal(double) constructor.
posted 3 weeks ago
Also work out the inheritance hierarchy in that code; it has a serious error in.
brevity is the soul of wit - shakepeare. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database