其他分享
首页 > 其他分享> > 小白之旅6

小白之旅6

作者:互联网

一. 方法

1.1 方法的好处

提高代码的复用性
隐藏了功能的实现细节

1.2 方法的组成

1.3 方法的定义和调用

1.4 参数列表

1.5 返回类型

表示该方法在运行完毕后会返回一个指定类型的结果给调用者

1.6 return关键字

注:一旦遇到了return,无论是否有数据的返回,方法都会立即结束。

二. 方法的重载

概念:在同一个类中,方法名相同参数列表不同的若干个方法就形成了方法的重载。
参数列表不同指的是参数的个数不同、类型不同、个数类型都不同、顺序不同

三. 可变参数

四. 值传递和引用传递

值传递:传递的数据类型是基本数据类型,这些数据存在于栈内存中,会随着方法的弹栈而被释放

<span class="xml"><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-function"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>public<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>static<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>void<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-title"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>main<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-params"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>(String[] args)<span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"></<span class="hljs-title">span</span>></span>{
    <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>int<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> a = <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>3<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>;
    f(a);
    System.<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>out<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>.println(a);
}
<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-function"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>public<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>static<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>void<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-title"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>f<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-params"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>(<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>int<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> num)<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>{
    num++;
}
结果:a还是<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>3<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>
`<span class="hljs-tag"></<span class="hljs-title">pre</span>></span>

引用传递:传递的数据类型的引用数据类型,这些数据存在于堆内存中,随着方法的弹栈这些数据仍旧在堆中不会被释放

<span class="hljs-tag"><<span class="hljs-title">pre</span>></span>`<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-function"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>public<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>static<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>void<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-title"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>main<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-params"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>(String[] args)<span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"></<span class="hljs-title">span</span>></span>{
    <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>int<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>[] arr = {<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>1<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>,<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>2<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>,<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>3<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>,<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>4<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>};
    d(arr);
    System.<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>out<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>.println(arr[<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>0<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>]);
}
<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-function"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>public<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>static<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>void<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span> <span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-title"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>d<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-params"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>>(<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-keyword"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>int<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>[] arr)<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>{
    arr[<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>0<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>]++;
}
结果:arr[<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>0<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>]变成了<span class="hljs-tag"><<span class="hljs-title">span</span> <<span class="hljs-attribute">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-keyword"</span>></span>class<span class="hljs-tag"></<span class="hljs-title">span</span>></span>=<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-string"</span>></span>"hljs-number"<span class="hljs-tag"></<span class="hljs-title">span</span>></span>><span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-number"</span>></span>2<span class="hljs-tag"></<span class="hljs-title">span</span>></span><span class="hljs-tag"></<span class="hljs-title">span</span>></span>
`<span class="hljs-tag"></<span class="hljs-title">pre</span>></span>

<span class="hljs-tag"><<span class="hljs-title">span</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">"hljs-preprocessor"</span>></span>## 五. 递归<span class="hljs-tag"></<span class="hljs-title">span</span>></span>

概念:方法直接或者间接地调用自身
问题:StackOverflowError:栈溢出
要素:  
`<span class="hljs-tag"></<span class="hljs-title">pre</span>></span></span>
`</pre>

标签:classspan,span,string,keyword,小白,hljs,class
来源: https://www.cnblogs.com/demonycw/p/11306168.html