difference.java

来自「Thinking in Java 习题答案源码打包」· Java 代码 · 共 53 行

JAVA
53
字号
// reusing/Difference.java
// TIJ4 Chapter Reusing, Exercise 18, page 265
/* Create a class with a static final field and a final field and demonstrate
 * the difference between the two.
 */
import java.util.*;


class Test
{
	Test()
	{
		System.out.println( "Test()" );
	}
}



public class Difference
{
	private String name;


	public Difference( String s )
	{
		name = s;
	}


	static final Test sft = new Test(); // constant reference address
	private final Test ft = new Test();
	static final String SFS = "static final"; // class constant
	private final String fs = "final";
	private static Random rand = new Random();
	static final int SFI = rand.nextInt(); // class constant
	private final int fi = rand.nextInt();


	public String toString()
	{
		return ( name + ": " + sft + ", " + ft + ", " + SFS + ", " + fs + ", " + SFI + ", " + fi );
	}

	public static void main( String[] args )
	{
		Difference d1 = new Difference( "d1" );
		Difference d2 = new Difference( "d2" );
		Difference d3 = new Difference( "d3" );
		System.out.println( d1 );
		System.out.println( d2 );
		System.out.println( d3 );
	}
}

⌨️ 快捷键说明

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