Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    2
    ReputationRep:
    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()?
    Offline

    17
    ReputationRep:
    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
    Code:
    private void sayHi() {
      System.out.println("Hello there";);
    }
    a method that returns a value
    Code:
    private String getHelloMessage() { 
       return "Hello there";
    }
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What's your favourite Christmas sweets?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.