⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdn_文档中心_一步一步学java(第四课 方法、值传递、this关键字).htm

📁 csdn10年中间经典帖子
💻 HTM
📖 第 1 页 / 共 4 页
字号:
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">标</SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-hansi-font-family: 'Times New Roman'">:掌握</SPAN><SPAN 
            lang=EN-US style="mso-ansi-language: EN-US">Java</SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-hansi-font-family: 'Times New Roman'">方法的声明和调用方式</SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><FONT 
            size=3><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代</SPAN><SPAN 
            lang=EN-GB><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; 
            </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">码:</SPAN></FONT></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
            lang=EN-GB style="mso-fareast-font-family: 楷体_GB2312">/*<SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">范例名称:</SPAN><SPAN 
            lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312">Java</SPAN><SPAN 
            style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">方法使用举例</SPAN><SPAN 
            lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><o:p></o:p></SPAN></FONT></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
            lang=EN-GB style="mso-fareast-font-family: 楷体_GB2312"><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>* <SPAN 
            style="mso-tab-count: 1">&nbsp; </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">源文件名称:</SPAN><SPAN 
            lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312">Test.java<o:p></o:p></SPAN></FONT></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
            lang=EN-GB style="mso-fareast-font-family: 楷体_GB2312"><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>*<SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">要</SPAN><SPAN 
            lang=EN-GB style="mso-fareast-font-family: 楷体_GB2312"><SPAN 
            style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">点:</SPAN><SPAN 
            lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><o:p></o:p></SPAN></FONT></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
            lang=EN-GB style="mso-fareast-font-family: 楷体_GB2312"><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>* <SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>1. </SPAN><SPAN 
            style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">方法形参、实参的作用和用法</SPAN><SPAN 
            lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><o:p></o:p></SPAN></FONT></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><FONT size=3><SPAN 
            lang=EN-GB style="mso-fareast-font-family: 楷体_GB2312"><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>*<SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>2. </SPAN><SPAN 
            style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">返回值及返回值类型</SPAN><SPAN 
            lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><o:p></o:p></SPAN></FONT></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>*/<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3>public class 
            Test{<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>public int<SPAN style="mso-spacerun: yes">&nbsp; 
            </SPAN>method1(int a , int b, int c){<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>int k = a + b + c;<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>return k;<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>}<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>public static void main(String[] 
            args){<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>Test t = new Test();<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>int j = t.method1(3,4,5);<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>System.out.println("the result is:" + 
            j);<o:p></o:p></FONT></SPAN></P>
            <P class=a2 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB 
            style="mso-fareast-font-family: 楷体_GB2312"><FONT size=3><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>}<o:p></o:p></FONT></SPAN></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN 
            lang=EN-GB style="mso-fareast-font-family: 楷体_GB2312"><FONT 
            size=3><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; 
            </SPAN>}</FONT></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN 
            lang=EN-GB><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><FONT 
            size=3><SPAN lang=EN-US style="mso-ansi-language: EN-US"><SPAN 
            style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN 
            lang=EN-GB>Java</SPAN><SPAN 
            style="FONT-FAMILY: 黑体; mso-ascii-font-family: 'Times New Roman'">方法使用举例</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><FONT 
            size=3><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">案例文件:</SPAN><SPAN 
            lang=EN-GB>Test.java</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><FONT 
            size=3><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目</SPAN><SPAN 
            lang=EN-GB><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; 
            </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">标:</SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-hansi-font-family: 'Times New Roman'">掌握</SPAN><SPAN 
            lang=EN-US style="mso-ansi-language: EN-US">Java</SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-hansi-font-family: 'Times New Roman'">方法的声明和调用方式</SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><FONT 
            size=3><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代</SPAN><SPAN 
            lang=EN-GB><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; 
            </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">码:</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0; mso-para-margin-left: 1.0gd"><FONT 
            size=3><SPAN lang=EN-GB>/*<SPAN style="mso-tab-count: 1"> 
            </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">范例名称:</SPAN><SPAN 
            lang=EN-GB>Java</SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法使用举例</SPAN><SPAN 
            lang=EN-GB>2</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0; mso-para-margin-left: 1.0gd"><FONT 
            size=3><SPAN lang=EN-GB><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>* <SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">源文件名称:</SPAN><SPAN 
            lang=EN-GB>Test.java</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0; mso-para-margin-left: 1.0gd"><FONT 
            size=3><SPAN lang=EN-GB><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>*<SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">要</SPAN><SPAN 
            lang=EN-GB><SPAN style="mso-spacerun: yes">&nbsp; 
            </SPAN></SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">点:</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0; mso-para-margin-left: 1.0gd"><FONT 
            size=3><SPAN lang=EN-GB><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>* <SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>1. </SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法参数匹配</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0; mso-para-margin-left: 1.0gd"><FONT 
            size=3><SPAN lang=EN-GB><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>*<SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>2. </SPAN><SPAN 
            style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回值的使用</SPAN></FONT></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB><FONT size=3><SPAN 
            style="mso-spacerun: yes">&nbsp;</SPAN>*/</FONT></SPAN></P>
            <P class=a2 
            style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB><FONT size=3>class Tool{</FONT></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public 
            Tool(int i){<o:p></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>}<o:p></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public 
            int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>add(int a , int b, 
            int c){<o:p></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>int k = a + b + c;<o:p></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 
            style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>return k;<o:p></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; 
            </SPAN>}<o:p></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 
            style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public void 
            add_display(int a , int b, int c){<o:p></o:p></SPAN></P>
            <P class=a 
            style="MARGIN: 6pt 0cm 6pt 10.5pt; TEXT-INDENT: 15.65pt; mso-para-margin-left: 1.0gd"><SPAN 
            lang=EN-GB 
            style="FONT-SIZE: 10.5pt; mso-fareast-font-family: 楷体_GB2312; mso-bidi-font-size: 12.0pt; mso-font-kerning: 22.0pt"><SPAN 

⌨️ 快捷键说明

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