File tree Expand file tree Collapse file tree 3 files changed +91
-2
lines changed
Expand file tree Collapse file tree 3 files changed +91
-2
lines changed Original file line number Diff line number Diff line change 1+ package ABasic .A7Method ;
2+
3+ public class MethodReference {
4+ public static void main (String [] args ) {
5+ Person person =new Person ("name" , 18 , "black" );
6+ Person person1 =new Person ("name1" , 19 );
7+ System .out .println (person1 .toString ());
8+ copyAttribute (person , person1 );
9+ System .out .println (person1 .toString ());
10+ }
11+
12+ public static void copyAttribute (Person person , Person person1 ){
13+ person1 .setEyeColor (person .getEyeColor ());
14+ }
15+
16+ }
Original file line number Diff line number Diff line change 1+ package ABasic .A7Method ;
2+
3+ import java .util .Date ;
4+
5+ public class Person {
6+ private String name ;
7+ private int age ;
8+ private String eyeColor ;
9+ private Date birthday ;
10+
11+ /**
12+ * 构造方法具有两个特性:①名称是固定的,与类名相同; ②没有返回值,也不能有返回值
13+ * @param name
14+ * @param age
15+ * @param eyeColor
16+ */
17+ public Person (String name , int age , String eyeColor ){
18+ this .name =name ;
19+ this .age =age ;
20+ this .eyeColor =eyeColor ;
21+ }
22+
23+ /**
24+ * 构造方法的重载
25+ * @param name
26+ * @param age
27+ */
28+ public Person (String name , int age ){
29+ this .name =name ;
30+ this .age =age ;
31+ }
32+
33+ public String getName () {
34+ return this .name ;
35+ }
36+
37+ public void setName (String name ) {
38+ this .name =name ;
39+ }
40+
41+ public int getAge () {
42+ return this .age ;
43+ }
44+
45+ public void setAge (int age ) {
46+ this .age =age ;
47+ }
48+
49+ public String getEyeColor () {
50+ return eyeColor ;
51+ }
52+
53+ public void setEyeColor (String eyeColor ) {
54+ this .eyeColor = eyeColor ;
55+ }
56+
57+ public Date getBirthday () {
58+ return birthday ;
59+ }
60+
61+ public void setBirthday (Date birthday ) {
62+ this .birthday = birthday ;
63+ }
64+
65+ /**
66+ * 重载Object的toString()方法
67+ */
68+ @ Override
69+ public String toString () {
70+ String string ="name: " +name +", age: " +age +", eyeColor: " +eyeColor ;
71+ return string ;
72+ }
73+ }
Original file line number Diff line number Diff line change 1- package ABasic .A4String ;
1+ package ABasic .A7Method ;
22
3- public class StringBufferBuilder {
3+ public class StringMethodReference {
44 public static void main (String [] args ) {
55 stringMethod ();
66 }
You can’t perform that action at this time.
0 commit comments