• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Cannot instantiate the type?  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got the program with no apparent errors, but am unable to run it due to three little problems.... On lines 25, 27, and 29 I am getting an error message that says "Cannot instantiate the type Health/Life/AutoInsurance" (each to their respective ones). Everything else is showing up as fine, so I'm not sure why this error is here, nor how to fix it. Is there something I've missed when trying to connect everything all together, or is there something else wrong? It's not offering any suggestions on how to fix it, so I'm stuck right at this final part.

 
Sheriff
Posts: 21500
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't create instances of abstract classes or interfaces. You can use them as reference types or return types, but the actual value must be the instance of a non-abstract class.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rachel Barnes wrote:I've got the program with no apparent errors...


Rob's basically covered your main problem, but there are several redundancies in your classes which may eventually come to bite you.

1. If you have a Monthly premium, you don't need an Annual one; and personally, I'd store the latter. This isn't just nitpicking; in the real world there's a distinct possibility that such a construct is illegal, since it could theoretically be used to implement a "penny-shaving" scam.

2. If your superclass already has an AnnualPremium, you don't need it in your subclasses.

Also: floating-point types are generally not what you want for values involving money; you're usually better off using BigDecimal. For more information, read this or (a slightly simpler version) this.

Winston
 
Rachel Barnes
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:You can't create instances of abstract classes or interfaces. You can use them as reference types or return types, but the actual value must be the instance of a non-abstract class.




Took care of the 'abstract' issue and it's running now. However, I'm not receiving the right output. The policy number and monthly premium are showing up as zero. The annual is fine. Can you help me locate where my problem is?

And for the other commenter, the Annual bit is required for the assignment for whatever reason, so I have to keep that.
 
Rob Spoor
Sheriff
Posts: 21500
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lines 53 and 54 have it the wrong way around - you're assigning the field value (still 0) to the parameter.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!