關(guān)于java語言程序的問題
1、對于java應(yīng)用程序來說,static靜態(tài)變量和方法的含義。
import java.io.*;
public class Iamxiao
{
static String st1="中國將收復(fù)臺灣!";
/*此處必須定義為靜態(tài),否則系統(tǒng)會提示在main主程序中找不到st1變量。
定義為public也不行,這是為什么呀?
*/
public static void main(String args[])
{
Iamxiao2 Iamxiao1;
Iamxiao1=new Iamxiao2();
System.out.
}
}
以下再寫一個應(yīng)用程序進(jìn)行實驗,此程序依舊運(yùn)行時報錯。
class _beidy
{
String st1="中國將收復(fù)臺灣!";
System.out.println("Hello the world!"+st1);
}
public class _diaoyz
{
public static void main(String args[])
{
_beidy _newobj=new _beidy();
}
}
以下再寫成小應(yīng)用程序進(jìn)行實驗。
class _beidy
{
/*總算明白了,這正是java語言要求的封裝性。
*/
public void _beidyp()
{
String st1="中國將收復(fù)臺灣!";
System.out.println("Hello the world!"+st1);
}
}
public class _diaoyz
{
public static void main(String args[])
{
_beidy _newobj=new _beidy();
_newobj._beidyp();
}
}
以下再進(jìn)行測試。
class _beidy
{
String st1="中國將收復(fù)臺灣!";
//System.out.println("Hello the world!"+st1);
}
public class _diaoyz
{
public static void main(String args[])
{
_beidy _newobj=new _beidy();
System.out.println("Hello the world!"+_newobj.st1);
/*通過成員函數(shù)進(jìn)行類的實例對象的調(diào)用。輸出語句不能直接放
到一個類的定義下嗎?
*/
}
}
2、以下示例讓我們了解類名的定義,須定義為$,_,字母開頭的字符串,其長度沒有限制,
也就是受限于你的操作系統(tǒng)文件名的長度。文件確實可以超長,已做實驗。
import java.io.*;
public class $Sta1
{
static String st1="我是肖大靳!"; //此處必須定義為靜態(tài)。
public static void main(String args[])
{
$Sta1 sta1_o;
sta1_o=new $Sta1();
System.out.println("Hello the world!"+st1);
}
}
/*文件超長的例子。類名絕對不能超長,windows98下為235個字符長。
以下所定義的類名為最長,多加一個2即會報錯。
*/
class _beidy1212121212121212121212121212122323434433245234524534523452452452452452452452452524524245245245245245245245424242452424242424524524245245245245245243524524524524352345243524245242424234524352432222222222222222222222222222222222222
{
public void init()
{
String st1="中國將收復(fù)臺灣!";
System.out.println("Hello the world!"+st1);
}
}
public class _diaoyz
{
public static void main(String args[])
{
// _beidy _newobj=new _beidy();
// System.out.println("Hello the world!"+_newobj.st1);
//_newobj.init();
_beidy1212121212121212121212121212122323434433245234524534523452452452452452452452452524524245245245245245245245424242452424242424524524245245245245245243524524524524352345243524245242424234524352432222222222222222222222222222222222222 _newobj=new _beidy1212121212121212121212121212122323434433245234524534523452452452452452452452452524524245245245245245245245424242452424242424524524245245245245245243524524524524352345243524245242424234524352432222222222222222222222222222222222222();
_newobj.init();
}
|
新聞熱點
疑難解答