Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小雨青年
Java Demo
提交
89be344a
J
Java Demo
项目概览
小雨青年
/
Java Demo
通知
53
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Java Demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
89be344a
编写于
12月 04, 2021
作者:
小雨青年
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 类
上级
a027e42d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
89 addition
and
14 deletion
+89
-14
README.md
README.md
+9
-0
demo.iml
demo.iml
+0
-14
src/main/java/com/example/demo/controller/ClassController.java
...ain/java/com/example/demo/controller/ClassController.java
+39
-0
src/main/java/com/example/demo/tool/Cat.java
src/main/java/com/example/demo/tool/Cat.java
+24
-0
src/main/java/com/example/demo/tool/RagdollCat.java
src/main/java/com/example/demo/tool/RagdollCat.java
+17
-0
未找到文件。
README.md
浏览文件 @
89be344a
...
...
@@ -3,3 +3,12 @@
配套文章
[
【七日阅书】1 计算思维和Java特性《Java程序设计与计算思维》
](
https://blog.csdn.net/diandianxiyu_geek/article/details/121660902?spm=1001.2014.3001.5501
)
[
【七日阅书】2 Java的数据类型和流程控制《Java程序设计与计算思维》
](
https://blog.csdn.net/diandianxiyu_geek/article/details/121681529?spm=1001.2014.3001.5501
)
[
【七日阅书】3 字符串、数组、集合、泛型《Java程序设计与计算思维》
](
https://blog.csdn.net/diandianxiyu_geek/article/details/121703793?spm=1001.2014.3001.5501
)
demo.iml
浏览文件 @
89be344a
<?xml version="1.0" encoding="UTF-8"?>
<module
org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule=
"true"
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"FacetManager"
>
<facet
type=
"web"
name=
"Web"
>
<configuration>
<webroots
/>
<sourceRoots>
<root
url=
"file://$MODULE_DIR$/src/main/java"
/>
<root
url=
"file://$MODULE_DIR$/src/main/resources"
/>
</sourceRoots>
</configuration>
</facet>
<facet
type=
"Spring"
name=
"Spring"
>
<configuration
/>
</facet>
</component>
<component
name=
"NewModuleRootManager"
LANGUAGE_LEVEL=
"JDK_1_8"
>
<output
url=
"file://$MODULE_DIR$/target/classes"
/>
<output-test
url=
"file://$MODULE_DIR$/target/test-classes"
/>
...
...
src/main/java/com/example/demo/controller/ClassController.java
0 → 100644
浏览文件 @
89be344a
package
com.example.demo.controller
;
import
com.example.demo.tool.Cat
;
import
com.example.demo.tool.RagdollCat
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/"
)
public
class
ClassController
{
@GetMapping
(
"/class"
)
public
void
classDemo
(){
//对象就是类的实例化
Cat
tangguo
=
new
Cat
();
String
catName1
=
tangguo
.
formatName
();
System
.
out
.
print
(
catName1
);
System
.
out
.
print
(
"\r\n"
);
tangguo
.
setAge
(
3
);
//私有变量通过方法赋值
tangguo
.
name
=
"糖果"
;
//公开变量可以直接赋值
String
catName
=
tangguo
.
formatName
();
System
.
out
.
print
(
catName
);
System
.
out
.
print
(
"\r\n"
);
tangguo
.
printAge
();
}
@GetMapping
(
"/extends"
)
public
void
extendsDemo
(){
RagdollCat
ragdollCat
=
new
RagdollCat
();
ragdollCat
.
name
=
"小布"
;
ragdollCat
.
say
();
String
catName
=
ragdollCat
.
formatName
();
System
.
out
.
print
(
catName
);
System
.
out
.
print
(
"\r\n"
);
System
.
out
.
print
}
}
src/main/java/com/example/demo/tool/Cat.java
0 → 100644
浏览文件 @
89be344a
package
com.example.demo.tool
;
public
class
Cat
{
//公共的类
public
Cat
(){
//构造函数
System
.
out
.
print
(
"我是构造函数,实例化的时候自动调用\r\n"
);
name
=
"默认猫名字"
;
}
private
int
age
=
1
;
//私有变量 默认值
public
String
name
;
//公开变量
public
void
setAge
(
int
age
){
this
.
age
=
age
;
}
public
void
printAge
(){
System
.
out
.
print
(
age
);
}
public
String
formatName
(){
//公开方法
return
"猫的名字是:"
+
name
;
//返回值
}
}
src/main/java/com/example/demo/tool/RagdollCat.java
0 → 100644
浏览文件 @
89be344a
package
com.example.demo.tool
;
/**
* 布偶猫是猫的子类,继承了猫类
*/
public
class
RagdollCat
extends
Cat
{
//重写了方法
public
String
formatName
(){
return
"布偶猫的名字是:"
+
name
+
"\r\n"
;
}
//子类扩展出了新的方法
public
void
say
(){
System
.
out
.
print
(
"我是布偶猫\r\n"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录