The Student Room Group

Writing an instance method returning nothing

How do you write an instance method that returns no argument and value? This is in Java.

For example is it:

public string name()
{
name()
}

or:

public string name()?
Reply 1
How do you write an instance method that returns no argument and value? This is in Java.

You can't because what you said doesn't make sense. Here's why.

1) A method that returns no value is a void method.
2) Methods don't return arguments only values. They accept arguments only.

Void method
private void sayHi() {
System.out.println("Hello there":wink:;
}


a method that returns a valueprivate String getHelloMessage() {
return "Hello there";
}

Quick Reply

Latest

Trending

Trending