0

I am trying to create a basic method to check the whether a person is "Adult" or "Minor". I created two classes viz., Lessons.java (main class) and method.java (method class). When I run the program, I get following result:

"run:

Enter the age: 12

lessons.method@55f96302BUILD SUCCESSFUL (total time: 3 seconds)"

What is lessons.method@55f96302 ??? And how to resolve it??

My codes are:

Lessons.java (main class)

package lessons;

import java.util.Scanner;

public class Lessons {


public static void main(String[] args) {
    method b = new method();
    Scanner input=new Scanner(System.in);
    System.out.print ("Enter the age: ");
    int age=input.nextInt();

    b.simplemessage(age);
    System.out.print(b);


    }

  }

method.java (method class)

package lessons;
public class method {
public String simplemessage(int age){
if (age >= 18)
return "Adult";
 else
return "Minor";
}
}

Any helps??

Vaibhav Agarwal
  • 975
  • 1
  • 7
  • 22

1 Answers1

2
b.simplemessage(age);
System.out.print(b);

Your code calls the simplemessage method and does nothing with the return value. Then it prints the return value of b.toString().

It should be

System.out.print(b.simplemessage(age));
pp_
  • 3,435
  • 4
  • 19
  • 27
  • thanks for the help. I modified my System.out.print code and it worked. – Vaibhav Agarwal Feb 21 '16 at 02:56
  • Hi @VaibhavAgarwal if this answer has solved your question please consider [accepting it](http://meta.stackexchange.com/q/5234/179419) by clicking the check mark. – pp_ Feb 22 '16 at 05:21