2012-01-12 39 views

回答

11

out是一個靜態字段,其中包含對象的引用PrintStream對象。

println不是一種靜態方法。

這裏是out變量的System.java

/** 
* The "standard" output stream. This stream is already 
* open and ready to accept output data. Typically this stream 
* corresponds to display output or another output destination 
* specified by the host environment or user. 
* <p> 
* For simple stand-alone Java applications, a typical way to write 
* a line of output data is: 
* <blockquote><pre> 
*  System.out.println(data) 
* </pre></blockquote> 
* <p> 
* See the <code>println</code> methods in class <code>PrintStream</code>. 
* 
* @see  java.io.PrintStream#println() 
* @see  java.io.PrintStream#println(boolean) 
* @see  java.io.PrintStream#println(char) 
* @see  java.io.PrintStream#println(char[]) 
* @see  java.io.PrintStream#println(double) 
* @see  java.io.PrintStream#println(float) 
* @see  java.io.PrintStream#println(int) 
* @see  java.io.PrintStream#println(long) 
* @see  java.io.PrintStream#println(java.lang.Object) 
* @see  java.io.PrintStream#println(java.lang.String) 
*/ 
public final static PrintStream out = nullPrintStream(); 

聲明這是println方法的樣子:

/** 
* Terminates the current line by writing the line separator string. The 
* line separator string is defined by the system property 
* <code>line.separator</code>, and is not necessarily a single newline 
* character (<code>'\n'</code>). 
*/ 
public void println() { 
newLine(); 
} 
2

「out」是具有Stream值的靜態公共字段。

public final class System { 
    public final static PrintStream out = nullPrintStream(); 
... 
} 
2

out是類型爲PrintStream的靜態字段。閱讀here

2

System是一類。 outSystem類的靜態字段,其類型爲PrintStreamprintlnPrintStream類的實例方法。

只要看看the javadoc,你就會得到你要找的所有信息。

2

Source Page

System.out.println()

System是一個內置類存在於java.lang包。 該類有一個final修飾符,這意味着它不能被其他類繼承。 它包含預定義的方法和字段,其提供設施,如標準輸入,輸出等

out是靜態最終字段(即,可變的)在系統類,這是該類型PrintStream(的內置類,包含打印不同數據值的方法)。 必須使用類名來訪問靜態字段和方法,所以(System.out)。

out這裏表示PrintStream類型的參考變量。

println()是用於打印數據值的PrintStream類中的公共方法。

int i = 3; 
System.out.println(i); 

上面的代碼打印值: 因此訪問方法在PrintStream的類中,我們使用out.println()

例如(作爲非靜態方法和字段只能通過使用參考變量被訪問)在屏幕上顯示3,並將控制權交給下一行。

+1

[類似的問題1](http://stackoverflow.com /問題/ 3406703 /最新-的含義-的系統中取的println合的java/11202369#11202369), [類似問題2](http://stackoverflow.com/questions/10004856/just-wondering -System中取調用println/11202355#11202355) – 2012-06-26 09:28:19

0

問:要找到S的長度在給定的代碼,你有什麼替代答案就寫?

class Test{ 

     static String S="java"; 

     public static void main(String[] args) { 

     System.out.println(Ans); 

     } 

} 

Ans: Test.S.length() 
  1. 在此,S爲存在於試驗類

  2. 所以String類型的靜態變量,靜態變量是使用class_name.static_variable_name作爲Test.S

  3. 要查找長度訪問靜態變量S的,長度()方法用於String類的,其中S是一個對象,我們知道對象可以訪問方法S.length()

相同的概念在的System.out.println()用作:

class System{ 

     static PrintStream out; 

} 
  1. 系統是CLASS_NAME

  2. 出存在於系統類類型PrintStream的靜態變量。它也是同一類的PrintStream類和訪問方法println()的對象。

相關問題