集册 Java实例教程 toString方法

toString方法

欢马劈雪     最近更新时间:2020-01-02 10:19:05

424
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
toString方法

public class TestToString

{
/*
时代Java公众号 - nowjava.com 提 供
*/

    public static void main(String[] args)

    {

    Employee emp = new Employee("A", "B");

        System.out.println(emp.toString());


        int x = 50;

        String s = new Integer(x).toString();

        String s1 = "" + x;

        System.out.println(s);

        System.out.println(s1);

    }


}


class Employee

{

  private String lastName;
  /*来自 
   时 代 J a v a 公 众 号 - N o w J a v  a . c o m*/

  private String firstName;


  public Employee(String lastName, String firstName)

  {

    this.lastName = lastName;

    this.firstName = firstName;

  }


  public String toString()

  {

    return 
展开阅读全文