Re: void type not allowed in println(). Was Re: Inheritance and lousy Frame
- From: "NickName" <dadada@xxxxxxxx>
- Date: 12 Jan 2007 12:27:29 -0800
Ian Wilson wrote:
NickName wrote:[...]
Now, a new question arises,
};
The above attempt failed, err msg:
"MammalClass.java": 'void' type not allowed here at line 24, column 33
Println cannot print nothingness.
You can fix this in one of two ways ...
1)
Change speed() to
public String speed() {
return "30 mph";
}
OR
2)
Change
System.out.println(pet.speed());
to
pet.speed();
Don't do both changes :-)
A note on naming ...
I'd name your existing speed() as printSpeed()
I'd name the revised speed() in (1) as getSpeed()
Designwise, maybe `public int getMPH()` would be better?
Thank you, it chose option 2, it works great.
.
- References:
- Inheritance and lousy Frame
- From: NickName
- Re: Inheritance and lousy Frame
- From: Ian Wilson
- Re: Inheritance and lousy Frame
- From: NickName
- Re: Inheritance and lousy Frame
- From: NickName
- Re: Inheritance and lousy Frame
- From: Ian Wilson
- Re: Inheritance and lousy Frame
- From: NickName
- Re: void type not allowed in println(). Was Re: Inheritance and lousy Frame
- From: Ian Wilson
- Inheritance and lousy Frame
- Prev by Date: Re: File Read in 2 JVM
- Next by Date: Re: Inheritance and lousy Frame
- Previous by thread: Re: void type not allowed in println(). Was Re: Inheritance and lousy Frame
- Next by thread: Re: Inheritance and lousy Frame
- Index(es):
Relevant Pages
|