Answers for "public string tostring() {"

0

public string tostring() {

public class MyClass{

  // An example class with two arbitrary attributes
  private int myInt = 5;
  private String myString = "Hello World";
  
  // toString() is defined by default in Java, so the @Override is necessary
  @Override
  public String toString(){
    // Note that the result string can be anything you want
    return "MyClass Object (%s, %d)".format(this.myInt, this.myString);
  }
}
Posted by: Guest on March-21-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language