Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

error cannot be instantiated  RSS feed

 
william johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on this project and cannot seem to ficure it out. First post so thanks in advance. Really struggling with java...

Here's my error
java:8: Circle is abstract; cannot be instantiated
Circle c1 = new Circle(2.5, 22, 44);


EDIT by mw: Added Code Tags, as pete suggested below.
[ August 26, 2007: Message edited by: marc weber ]
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the forum!

A word of suggestion. If you can, when you post code, please use code tags. This will make your code more readable. To do this, after you have pasted your code into the message editor window, highlight a block of code and press the "code" button down below the message window. Please do this for every block of code.

Now as to your problem, you will learn to take error messages to heart as they usually tell you what is wrong. Here you are taking an abstract class, Circle, and trying to instantiate it with "new Circle(....)". And as you are finding out, you can't do this. You need to create a new class, a concrete class that extends Circle, and then instantiate that. Something like:


All abstract methods in the Circle class MUST be overridden in the concrete child class. If this is unclear, please read up on abstract classes either in the sun tutorials, in google, or in your textbook.

Good luck!

/Pete
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Just to expand a little on what pete said above...

An abstract class usually contains one or more abstract methods that do not have method bodies. This makes an abstract class "incomplete," because it can't function, and therefore it cannot be instantiated. When you extend an abstract class, you need to "complete" the class by providing method bodies (implementation) for any abstract methods by overriding these methods.
 
william johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First I apologize about the code tags, I knew better. I appreciate the replies. I'm new with java and the learning curve is rather large. I honestly do not know where to put


so I have the book open and I will relook at my code and follow up.

THanks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!