Hello, very good, I have a main that calls a method to display the content of an object on the screen, the main is this:
class Main
{
/**
* main method
* @param args arguments
*/
public static void main(String args[])
{
//Create a result
Result R = new Result("Ra.one",12,93,84);
//display a result
R.display();
}
}
What I do in that method to test that everything is fine is to get a message on the screen and nothing is returned... I do this:
public String display() {
StringBuilder sb = new StringBuilder();
sb.append("Hola que tal como estamos " );
return sb.toString();
}
It doesn't return anything, I don't understand why. I want the Display method to behave like a toString.
Your method doesn't "display" a string, it just returns it. If you want to display a string in the console, the common way is to use
System.out
, for exampleAs you have the code you will have to do:
Or in your method
display()
include the line that shows it before thereturn
: