invalid method declaration; return type required
Im pretty new to Java (Taking my first class, AP Computer Science no less)
The assignment is to write a graphical program that features the property of inheritance and uses constructors.
Im drawing a creeper from minecraft, ive been tryin to troubleshoot it but im stumped :@:
help please?
__________________________________________________ ________________ Code:
import java.awt.*;
import java.applet.*;
public class lab09 extends Applet
{
public void paint(Graphics g)
{
MinecraftCreeper jack = new MinecraftCreeper(g);
}
}
class MinecraftCreeper extends Creeper
{
public MinecraftCreeper(Graphics g)
{
super(g);
}
}
class Creeper
{
public Creeper(Graphics g)
{
g.setColor(new Color(136,192,109));
g.fillRect(400,60,100,100);
g.setColor(new Color(0,0,0));
g.fillRect(420,80,20,20);
g.fillRect(460,80,20,20);
g.fillRect(440,100,20,30);
g.fillRect(430,110,10,30);
g.fillRect(460,110,10,30);
}
}
class CreeperTorso extends Torso
{
public Torso(Graphics g)
{
g.setColor(new Color(0,0,0));
g.fillRect(40,80,20,20);
}
}
Re: invalid method declaration; return type required
Can you show the error message you ends up with?
Re: invalid method declaration; return type required
Inside the CreeperTorso class how can you define this?
Code:
public Torso(Graphics g)
{
g.setColor(new Color(0,0,0));
g.fillRect(40,80,20,20);
}
Do you know really what it is?
Re: invalid method declaration; return type required
Code:
class CreeperTorso extends Torso {
public Torso(Graphics g)
Hmmm!
Re: invalid method declaration; return type required
Quote:
Originally Posted by
Junky
Code:
class CreeperTorso extends Torso {
public Torso(Graphics g)
Hmmm!
What is extend does and how the constructor use. ;) Let see OP could find that.
Re: invalid method declaration; return type required
OK i cant believe i missed that....thanks for pointing it out guys! i have it now
Re: invalid method declaration; return type required
You are welcome.
BTW, are you working on with an IDE?
Re: invalid method declaration; return type required
Re: invalid method declaration; return type required
I haven't use JCreator. But most of the time IDE give a lots of hints. I just compiled your code in NetBeans, and it give the following.
Quote:
error: invalid method declaration; return type required
public Torso(Graphics g)
1 error
So looking at the pointed line of code, I can get some sense about the error. :) I believe that JCreator does the same.
Re: invalid method declaration; return type required
Quote:
Originally Posted by
Eranga
I haven't use JCreator. But most of the time IDE give a lots of hints. I just compiled your code in NetBeans, and it give the following.
So looking at the pointed line of code, I can get some sense about the error. :) I believe that JCreator does the same.
Yeah, it does, I dont know i just blanked out I guess when I was trying to figure out what was wrong. Haha, like I said though im a total newbie at this.
Re: invalid method declaration; return type required
Of course. With the practice you'll be able to catch those things. :) Same here when I start to coding.
May be that is one of the advantages that stick into one or two IDEs. Then you know from A-Z. Anyway, good luck with Java.