//静态方法
//不需要对象的方法,也不需要依靠实例变量
public static int min{int a,int b}{
//返回a和b的较小值
}
在使用时,用类的名称调用静态的方法:Math.min(88,76)
//非静态方法
//实例变量的值会影响play()方法
//以引用变量的名称调用非静态方法
//Song te=new Song();
//te.player();
public class Song{
String Song(String t){
title=t;
}
public void play(){
SoundPlayer player=new SoundPlayer();
player.playerSound(title);
}
}
静态变量:对于所有的实例来说是相同的,只有在创建对象时才会
初始化
静态的final变量是常数
//初始化方法1
public class FOO{
public static final double PI=3.141592653589793;
}
//初始化方法2
public class Bar{
public static final double BAR_SIGN;
static{
BAR_SIGN=(double)Math.random();
}
}