Re: void type not allowed in println(). Was Re: Inheritance and lousy Frame




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.

.



Relevant Pages

  • Re: void type not allowed in println(). Was Re: Inheritance and lousy Frame
    ... The above attempt failed, err msg: ... Println cannot print nothingness. ... You can fix this in one of two ways ... ...
    (comp.lang.java.programmer)
  • Re: Cant open messages/address book
    ... See if the info in the KB article helps you fix the problem. ... 192321 - Err Msg: Unable to Open Address Book, ... >I continue to receive email messages in Outlook Express, ... > but get an error message when I click the address button ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • rpc problem
    ... running HP-UX. ... The err msg is ... How can I fix this error? ...
    (comp.sys.hp.hpux)
  • Re: Program Error
    ... virus/trojan. ... But what exactly is err msg? ... > Does anyone know how to fix iezp.exe generated error when ... > windows boots?? ...
    (microsoft.public.win2000.applications)