Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5318c3d

Browse files
committed
Java第十天
1 parent601c98b commit5318c3d

31 files changed

+908
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//形式参数如果是基本类型,只需要传递该基本类型的值即可。
2+
classDemo {
3+
publicintsum(inta,intb) {
4+
returna +b;
5+
}
6+
}
7+
8+
classArgsDemo {
9+
publicstaticvoidmain(String[]args) {
10+
Demod =newDemo();
11+
12+
//变量
13+
intx =10;
14+
inty =20;
15+
intz =d.sum(x,y);
16+
17+
//常量
18+
inta =d.sum(10,20);
19+
20+
System.out.println(z);
21+
System.out.println(a);
22+
}
23+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//形式参数如果是引用类型:
2+
//具体类:该类的对象。
3+
//抽象类:该类的子类对象。
4+
//接口:该接口的实现类对象。
5+
//数组:数组的地址值。其实就是一个数组对象。
6+
7+
/*
8+
class Student {
9+
public void study() {
10+
System.out.println("好好学习,天天向上");
11+
}
12+
}
13+
14+
class StudentDemo {
15+
public void method(Student s) {
16+
s.study();
17+
}
18+
}
19+
20+
class ArgsDemo2 {
21+
public static void main(String[] args) {
22+
StudentDemo sd = new StudentDemo();
23+
Student s = new Student();
24+
sd.method(s);
25+
}
26+
}
27+
*/
28+
29+
/*
30+
abstract class Person {
31+
public abstract void study();
32+
}
33+
34+
class PersonDemo {
35+
public void method(Person p) {
36+
p.study();
37+
}
38+
}
39+
40+
class Student extends Person {
41+
public void study() {
42+
System.out.println("好好学习,天天向上");
43+
}
44+
}
45+
46+
class ArgsDemo2 {
47+
public static void main(String[] args) {
48+
PersonDemo pd = new PersonDemo();
49+
Person p = new Student();
50+
pd.method(p);
51+
}
52+
}
53+
*/
54+
interfacePerson {
55+
publicabstractvoidstudy();
56+
}
57+
58+
classPersonDemo {
59+
publicvoidmethod(Personp) {
60+
p.study();
61+
}
62+
}
63+
64+
classStudentimplementsPerson {
65+
publicvoidstudy() {
66+
System.out.println("好好学习,天天向上");
67+
}
68+
}
69+
70+
classArgsDemo2 {
71+
publicstaticvoidmain(String[]args) {
72+
PersonDemopd =newPersonDemo();
73+
Personp =newStudent();
74+
pd.method(p);
75+
}
76+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//如果返回值是一个基本数据类型,那么,返回的就是该基本类型的值。
2+
classDemo {
3+
publicintsum(inta,intb) {
4+
returna +b;
5+
}
6+
}
7+
8+
classReturnDemo {
9+
publicstaticvoidmain(String[]args) {
10+
intx =newDemo().sum(10,20);
11+
System.out.println(x);
12+
}
13+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//如果返回值是一个引用数据类型
2+
//类:返回的是该类的对象
3+
//抽象类:返回的是该抽象类的子类对象
4+
//接口:返回的是该接口的实现类对象
5+
/*
6+
class Student {
7+
public void study() {
8+
System.out.println("好好学习,天天向上");
9+
}
10+
}
11+
12+
class StudentDemo {
13+
public Student getStudent() {
14+
//Student s = new Student();
15+
//return s;
16+
17+
return new Student();
18+
}
19+
20+
public int sum(int a,int b) {
21+
return a + b;
22+
}
23+
}
24+
25+
class ReturnDemo2 {
26+
public static void main(String[] args) {
27+
StudentDemo sd = new StudentDemo();
28+
Student s = sd.getStudent(); //new Student();
29+
s.study();
30+
}
31+
}
32+
*/
33+
34+
/*
35+
abstract class Person {
36+
public abstract void study();
37+
}
38+
39+
class PersonDemo {
40+
public Person getPerson() {
41+
return new Student();
42+
}
43+
}
44+
45+
class Student extends Person {
46+
public void study() {
47+
System.out.println("好好学习,天天向上");
48+
}
49+
}
50+
51+
class ReturnDemo2 {
52+
public static void main(String[] args) {
53+
PersonDemo pd = new PersonDemo();
54+
Person p = pd.getPerson(); //new Student();
55+
p.study();
56+
}
57+
}
58+
*/
59+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//返回值类型是接口,其实返回的是接口的实现类对象
2+
interfacePerson {
3+
publicabstractvoidstudy();
4+
}
5+
6+
classPersonDemo {
7+
publicPersongetPerson() {
8+
returnnewStudent();
9+
}
10+
}
11+
12+
classStudentimplementsPerson {
13+
publicvoidstudy() {
14+
System.out.println("好好学习,天天向上");
15+
}
16+
}
17+
18+
classReturnDemo3 {
19+
publicstaticvoidmain(String[]args) {
20+
//PersonDemo pd = new PersonDemo();
21+
//Person p = pd.getPerson();
22+
//p.study();
23+
24+
//链式编程
25+
newPersonDemo().getPerson().study();
26+
}
27+
}

‎day10/code/03_包/Demo.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
packagecom.liuyi;
2+
3+
publicclassDemo {
4+
publicintsum(inta,intb) {
5+
returna +b;
6+
}
7+
}

‎day10/code/03_包/HelloWorld.java‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
包:其实就是文件夹
3+
作用:对类进行分类管理
4+
5+
包的划分:
6+
举例:
7+
学生的增加,删除,修改,查询
8+
老师的增加,删除,修改,查询
9+
工人的增加,删除,修改,查询
10+
A:按照功能分
11+
cn.itcast.add
12+
AddStudent
13+
AddTeacher
14+
AddWorker
15+
cn.itcast.delete
16+
DeleteStudent
17+
DeleteTeacher
18+
DeleteWorker
19+
cn.itcast.update
20+
cn.itcast.find
21+
B:按照模块分
22+
cn.itcast.student
23+
add
24+
delete
25+
update
26+
find
27+
cn.itcast.teacher
28+
add
29+
delete
30+
update
31+
find
32+
cn.itcast.worker
33+
add
34+
delete
35+
update
36+
find
37+
38+
定义包的格式:
39+
package 包名;
40+
41+
带包的编译和运行:
42+
手动式:
43+
A:编译带包的类文件
44+
B:自己手动创建包
45+
C:把编译生成的class文件放到包里面去
46+
D:运行即可,注意要带包名
47+
java cn.itcast.HelloWorld
48+
自动式:
49+
A:编译的时候带一个参数 -d
50+
javac -d . HelloWorld.java
51+
B:运行即可,注意要带包名
52+
java cn.itcast.HelloWorld
53+
54+
注意事项:
55+
package语句必须是程序的第一条可执行的代码
56+
package语句在一个java文件中只能有一个
57+
如果没有package,默认表示无包名
58+
*/
59+
packagecn.itcast;
60+
61+
classHelloWorld {
62+
publicstaticvoidmain(String[]args) {
63+
System.out.println("HelloWorld");
64+
}
65+
}

‎day10/code/03_包/Test.class‎

462 Bytes
Binary file not shown.

‎day10/code/03_包/Test.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packagecn.itcast;
2+
3+
/*
4+
导包格式
5+
import 包名..类名;
6+
7+
package,import,class有没有顺序关系(面试题)
8+
有。
9+
package --> import --> class
10+
唯一多个多个
11+
*/
12+
importcom.liuyi.Demo;
13+
14+
publicclassTest {
15+
publicstaticvoidmain(String[]args) {
16+
/*
17+
com.liuyi.Demo d = new com.liuyi.Demo();
18+
int result = d.sum(10,20);
19+
System.out.println(result);
20+
21+
com.liuyi.Demo d2 = new com.liuyi.Demo();
22+
int result2 = d2.sum(10,20);
23+
System.out.println(result2);
24+
25+
com.liuyi.Demo d3 = new com.liuyi.Demo();
26+
int result3 = d3.sum(10,20);
27+
System.out.println(result3);
28+
*/
29+
30+
Demod =newDemo();
31+
intresult =d.sum(10,20);
32+
System.out.println(result);
33+
}
34+
}
462 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp