tostring.java

来自「JAVA培训用实用代码」· Java 代码 · 共 26 行

JAVA
26
字号
class MyDate{
	private int day,month,year;	
	public MyDate(int d, int m, int y){
		day = d;	month = m; 	year = y;
	}
}

class YourDate{
	private int day,month,year;	
	public YourDate(int d, int m, int y){
		day = d;	month = m; 	year = y;
	}
	public String toString(){
		return  day + "-" + month + "-" + year;	
	}		
}

public class ToString{
	public static void main(String args[]){
		MyDate m = new MyDate(22,7,1964);
		System.out.println(m);
		System.out.println(m.toString());
		YourDate y = new YourDate(22,7,1964);
		System.out.println(y);	
	}	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?