Skip to content

Commit 61a91dc

Browse files
committed
aaaa
1 parent d033d3c commit 61a91dc

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

.idea/workspace.xml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

how2j_笔记/00_网址.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
4+
5+
6+
java基础网站:
7+
https://how2j.cn
8+
2196411859@qq.com 密码:默认
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.practise2;
2+
3+
/*实现某个接口,就相当于承诺了某种约定
4+
* 在设计LOL的时候,进攻类英雄有两种,一种是进行物理系攻击,一种是进行魔法系攻击
5+
这时候,就可以使用接口来实现这个效果。
6+
接口就像是一种约定,我们约定某些英雄是物理系英雄,那么他们就一定能够进行物理攻击。
7+
* */
8+
public class p01implements {
9+
public static void main(String[] args) {
10+
System.out.println("hello");
11+
}
12+
}
13+
14+
15+
//01.AD ,声明一个方法 physicAttack 物理攻击,但是没有方法体,是一个“空”方法
16+
interface AD {
17+
//物理伤害
18+
public void physicAttack();
19+
}
20+
//02.AP
21+
interface AP {
22+
public void magicAttack();
23+
}
24+
25+
26+
/* 02.设计一类英雄,能够使用物理攻击,这类英雄在LOL中被叫做AD
27+
类:ADHero
28+
继承了Hero 类,所以继承了name,hp,armor等属性
29+
30+
实现某个接口,就相当于承诺了某种约定
31+
32+
所以,实现了AD这个接口,就必须提供AD接口中声明的方法physicAttack()
33+
实现在语法上使用关键字 implements
34+
35+
class ADHero extends Hero implements AD{
36+
@Override
37+
public void physicAttack() {
38+
System.out.println("进行物理攻击");
39+
}
40+
}
41+
* */
42+
43+
44+
/*03.设计一类英雄,只能使用魔法攻击,这类英雄在LOL中被叫做AP
45+
类:APHero
46+
继承了Hero 类,所以继承了name,hp,armor等属性
47+
同时,实现了AP这个接口,就必须提供AP接口中声明的方法magicAttack()
48+
实现在语法上使用关键字 implements
49+
50+
51+
class APHero extends Hero implements AP{
52+
@Override
53+
public void magicAttack() {
54+
System.out.println("进行魔法攻击");
55+
}
56+
}
57+
* */
58+
59+
60+
//***04_设计一类英雄,既能进行物理攻击,又能进行魔法攻击
61+
/*
62+
63+
class ADAPHero extends Hero implements AD,AP{
64+
65+
@Override
66+
public void magicAttack() {
67+
System.out.println("进行魔法攻击");
68+
}
69+
70+
@Override
71+
public void physicAttack() {
72+
System.out.println("进行物理攻击");
73+
}
74+
}
75+
76+
* */

0 commit comments

Comments
 (0)