修改了工程目录

This commit is contained in:
法然
2022-07-25 01:52:06 +08:00
parent 5a9a7df4a3
commit 699829febc
54 changed files with 598 additions and 58 deletions

18
.vscode/launch.json vendored
View File

@@ -4,12 +4,18 @@
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Java Program",
"request": "launch",
"mainClass": ""
},
{
"type": "java",
"name": "Launch App",
"request": "launch",
"mainClass": "com.ykl.App"
},
{
"type": "java",
"name": "Launch Java Program",
"request": "launch",
"mainClass": ""
},
{
"type": "java",
"name": "Launch Java01HelloWorld",

24
.vscode/tasks.json vendored
View File

@@ -1,24 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++:build",
"command": "D:\\mingw\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: D:\\mingw\\mingw64\\bin\\g++.exe"
},
]
}

View File

@@ -1,8 +1,9 @@
## 1 类和对象
> 建模全宇宙,用有限的代码描述无限的世界
### 类的定义
属性和方法(变量和函数),对象即实例。放到一起就是对象。面相对象的本质就是以类的方式组织代码,以对象组织封装数据。
属性和方法(变量和函数),对象即实例。放到一起就是对象。面相对象的本质就是以类的方式组织代码,以对象组织封装数据。OOP:Object oriented programming
抽象,把共同的部分抽取出来,组成一个类。
@@ -89,10 +90,16 @@ public void setName(String name){
}
```
### this
调用重载的构造方法:
1. 可以在构造方法中通过this调用本类的另一个构造方法且必须置于第一行。
2. 可以通过this调用本类中带参或无参构造方法调用带参构造方法时需要按顺序传入设定的参数。
3. 在一个构造方法内只能调用一个构造方法。
4. 不能在类中普通成员方法内通过this调用构造方法。
### super
- 子类的构造函数会默认调用父类的无参构造函数。而且通过super()方法调用父类的构造器,必须放在子类构造器的第一行。
- 访问父类的构造函数:可以使用 super() 函数访问父类的构造函数,从而委托父类完成一些初始化的工作。应该注意到,子类一定会调用父类的构造函数来完成初始化工作,一般是调用父类的默认构造函数,如果子类需要调用父类其它构造函数,那么就可以使用 super() 函数。
- 访问父类的成员:如果子类重写了父类的某个方法,可以通过使用 super 关键字来引用父类的方法实现。
@@ -131,14 +138,17 @@ public class SuperExtendExample extends SuperExample {
}
```
### static
static方法和static变量和类加载器同时加载到内存中存储在静态方法区。
## 2 三大特性——封装
高内聚、低耦合。属性私有
高内聚、低耦合。属性私有
1. 隐藏实现的细节。将抽象性函式接口的实现细节部分包装、隐藏起来的方法。
2. 提高系统的安全性。在getset中对输入数据进行安全检查。封装可以被认为是一个保护屏障防止该类的代码和数据被外部类定义的代码随机访问。要访问该类的代码和数据必须通过严格的接口控制。
3. 提供统一的接口
4. 更容易理解与维护,也加强了程式码的安全性
4. 更容易理解与维护。
**实现封装的步骤**
@@ -151,6 +161,7 @@ public class SuperExtendExample extends SuperExample {
**继承的定义**
1. 继承就是子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方法,或子类从父类继承方法,使得子类具有父类相同的行为。
2. 继承本质上是一种代码复用的方法。也提高了代码的耦合程度。
3. 所有没有父类的类默认继承Object类。
```java
class 父类 {
@@ -250,6 +261,14 @@ public class TestSuperSub{
* 父类引用指向子类对象Parent p = new Child();
![](image/2022-07-11-15-48-30.png)
**多态的说明**
* 多态是方法的多态,属性没有多态。
* 被private/static/final定义的方法不能被重写。final类型的方法重写编译器会报错。static方法只能被同名函数重定义。
**类型转换**
* 向上转型,父类变量指向子类对象。向上转型是自动发生的
* 向下转型,父类变量转为子类变量。向下转型需要强制类型转换。
```java
class Shape {
void draw() {}
@@ -329,7 +348,7 @@ class Dog extends Animal {
**多态实现方法**
1. 重载重写
1. 重载重写、重定义(命名作用域屏蔽)
2. 接口实现
3. 抽象类和抽象方法
@@ -342,11 +361,14 @@ class Dog extends Animal {
* 重写的好处在于子类可以根据需要,定义特定于自己的行为。 也就是说子类能够根据需要实现父类的方法。重写方法不能抛出新的检查异常或者比被重写方法申明更加宽泛的异常。
* 对象的引用类型决定了对象能够访问的方法。对象具体调用的方法,取决于对象的实际类型。(引用类型和实际类型。)
为了满足里式替换原则,重写有以下三个限制:
- 子类方法的访问权限必须大于等于父类方法;
- 访问权限修饰符范围只能扩大,不能缩小。子类方法的访问权限必须大于等于父类方法;
- 子类方法的返回类型必须是父类方法返回类型或为其子类型。
- 子类方法抛出的异常类型必须是父类抛出异常类型或为其子类型。
- 抛出异常的范围只能缩小,不能扩大。子类方法抛出的异常类型必须是父类抛出异常类型或为其子类型。
使用 @Override 注解,可以让编译器帮忙检查是否满足上面的三个限制条件。

View File

@@ -2,12 +2,11 @@
## 1 抽象类
抽象类和抽象方法都使用 abstract 关键字进行声明。
* 如果一个类中包含抽象方法,那么这个类必须声明为抽象类。
* 任何子类必须重写父类的抽象方法,或者声明自身为抽象类。
抽象类和普通类最大的区别是,抽象类不能被实例化,只能被继承。
* 抽象类和抽象方法都使用 abstract 关键字进行声明。
* 抽象方法,是一种约束,只有方法的声明,没有方法的实现。如果一个类中包含抽象方法,那么这个类必须声明为抽象类。抽象类可以包含普通方法。
* 抽象类,非抽象子类必须实现抽象方法。任何子类必须重写父类的抽象方法,或者声明自身为抽象类。
* 抽象类和普通类最大的区别是,抽象类不能被实例化,只能被继承。
* 抽象类没有构造方法。
```java
public abstract class AbstractClassExample {
@@ -33,17 +32,19 @@ public class AbstractExtendClassExample extends AbstractClassExample {
```
## 2 接口
* 接口规范、定义规则、本质上是契约。
implements关键字
* 使用 implements 关键字可以变相的使java具有多继承的特性使用范围为类继承接口的情况可以同时继承多个接口接口跟接口之间采用逗号分隔
* 接口不能被实例化,接口中没有构造方法。必须重写接口中的方法。
* 接口是抽象类的延伸,在 Java 8 之前,它可以看成是一个完全抽象的类,也就是说它不能有任何的方法实现。
* 从 Java 8 开始,**接口也可以拥有默认的方法实现**,这是因为不支持默认方法的接口的维护成本太高了。在 Java 8 之前,如果一个接口想要添加新的方法,那么要修改所有实现了该接口的类,让它们都实现新增的方法。
* 接口的成员(字段 + 方法)默认都是 **public abstract**的,并且不允许定义为 private 或者 protected。从 Java 9 开始,**允许将方法定义为 private**,这样就能定义某些复用的代码又不会把方法暴露出去。
* 接口的成员(字段 + 方法)默认都是 **public abstract**的,并且不允许定义为 private 或者 protected。
* 接口的字段默认都是 **static 和 final** 的。

View File

@@ -0,0 +1,13 @@
# Java 内部类
## 概述
### 基本概念
内部类就是在一个类的内部定义一个类。
* 成员内部类
* 静态内部类
* 局部内部类
* 匿名内部类

View File

@@ -0,0 +1,37 @@
### 基本类型的类型转换
### 继承中的类型转换
* 向上转型。子类的对象可以转换成父类的变量。
* 向下转型。父类的变量可以转换成子类的变量。
**验证3种情况**
* 父类变量指向父类对象(父类方法)。父类变量强制转换子类变量(转换出错)。
* 子类变量指向子类对象(子类方法)。子类变量强制转换父类变量(多态子类方法)。
* 父类变量指向子类对象(多态子类方法)。父类变量强制转换子类变量(子类方法)。
```java
public class App02
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
Dog dd = new Dog();
Animal aa = new Animal();
Animal ad = new Dog();
dd.say(); //dog say
((Animal)dd).say();//dog say
aa.say();// animal say
// ((Dog) aa).say();// down
ad.say();//dog say
((Dog) ad).say();//dog say
}
}
```

View File

@@ -225,7 +225,7 @@
- 对于基本类型final 使数值不变;
- 对于引用类型final 使引用不变,也就不能引用其它对象,但是被引用的对象本身是可以修改的。
- 如果引用时类的成员变量,则必须当场赋值,否则编译会报错。
```java
final int x = 1;
// x = 2; // cannot assign value to final variable 'x'
@@ -235,7 +235,7 @@ y.a = 1;
**2. 方法**
声明方法不能被子类重写。
声明方法不能被子类重写。当使用final修饰方法时这个方法将成为最终方法无法被子类重写。但是该方法仍然可以被继承。
private 方法隐式地被指定为 final如果在子类中定义的方法和基类中的一个 private 方法签名相同,此时子类的方法不是重写基类方法,而是在子类中定义了一个新的方法。

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ConfPoetryConfig">
<option name="pathRules">
<list>
<option value=".*/config/[^/]+/[^/]+/((env)|(drm)|(log)|(meta)|(scheduler)|(serviceGroup)|(zdal)|(ci))/[^/]+" />
<option value=".*/config/[^/]+/dbSql/[^/]+" />
<option value=".*/conf/iac/[^/]+/((env)|(drm)|(log)|(meta)|(scheduler)|(serviceGroup)|(zdal)|(ci)|(sofamq)|(database))/[^/]+" />
<option value=".*/conf/iac/[^/]+/msg/(pub|sub)/[^/]+" />
</list>
</option>
</component>
</project>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="demo01" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="demo01" target="1.7" />
</bytecodeTargetLevel>
</component>
</project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/demo01/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/demo01/src/main/resources" charset="UTF-8" />
</component>
</project>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="archetype" />
<option name="name" value="archetype" />
<option name="url" value="http://mvn.cloud.alipay.com/nexus/content/groups/open" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

View File

@@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: junit:junit:4.11">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.hamcrest:hamcrest-core:1.3">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
</SOURCES>
</library>
</component>

11
Java源代码/lesson04/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/demo01/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

View File

@@ -2,6 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/demo01/demo01.iml" filepath="$PROJECT_DIR$/demo01/demo01.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/lesson04.iml" filepath="$PROJECT_DIR$/.idea/lesson04.iml" />
</modules>
</component>

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ykl</groupId>
<artifactId>demo01</artifactId>
<version>1.0-SNAPSHOT</version>
<name>demo01</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@@ -0,0 +1,22 @@
package com.ykl;
import com.ykl.example01.Animal;
import com.ykl.example01.Dog;
/**
* Hello world!
*
*/
public class App01
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
Dog dd = new Dog();
Animal ad = new Dog();
dd.say();
dd.eat();
ad.say();
ad.eat();
}
}

View File

@@ -1,8 +1,11 @@
package com.ykl.example01;
package com.ykl;
import com.ykl.example01.Animal;
import com.ykl.example01.Dog;
/**
* Hello world!
*
* 用来验证不同的类型转换方法,是否成功和最终输出的结果。
*/
public class App02
{
@@ -10,10 +13,14 @@ public class App02
{
System.out.println( "Hello World!" );
Dog dd = new Dog();
Animal aa = new Animal();
Animal ad = new Dog();
dd.say();
dd.eat();
ad.say();
ad.eat();
dd.say(); //dog say
((Animal)dd).say();//dog say
aa.say();// animal say
// ((Dog) aa).say();// down
ad.say();//dog say
((Dog) ad).say();//dog say
}
}

View File

@@ -0,0 +1,18 @@
package com.ykl;
import com.ykl.example01.Person;
/**
* Hello world!
* 用来验证初始化的执行顺序。
*/
public class App03
{
public static void main( String[] args )
{
Person person = new Person();
Person person3 = new Person();
person.say();
}
}

View File

@@ -0,0 +1,10 @@
package com.ykl.example01;
public class Animal {
public final void eat(){
System.out.println("animal eat");
}
public void say(){
System.out.println("animal say");
}
}

View File

@@ -0,0 +1,14 @@
package com.ykl.example01;
import com.ykl.example01.Animal;
public class Dog extends Animal{
// final方法默认不能被覆盖编译器报错。
// public void eat(){
// System.out.println("dog eat");
// }
public void say(){
System.out.println("dog say");
}
}

View File

@@ -1,9 +1,37 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/package com.ykl.example01;/**
*
*/
package com.ykl.example01;
import java.sql.SQLOutput;
/**
* @author yinkanglong
* @version : Person, v 0.1 2022-07-24 01:56 yinkanglong Exp $
*/public class Person {
*/
public class Person {
//静态变量
public static int age=10;
//静态方法
public static void say(){
System.out.println("静态方法执行了");
}
//代码快
{
System.out.println("普通代码块");
}
//静态代码快
static {
System.out.println("静态代码块");
}
public Person(){
System.out.println("构造器执行了");
}
}

View File

@@ -0,0 +1,51 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.ykl.example04;
/**
* @author yinkanglong
* @version : Outer, v 0.1 2022-07-24 13:19 yinkanglong Exp $
*/
public class Outer {
private int id;
public void out(){
System.out.println("outer method");
}
public class Inner{
public void in(){
System.out.println("inner method");
//成员内部类可以直接获取外部类的私有属性。
}
}
public static class InnerStatic{
}
public void method(){
class Inner{
public void inMehtod(){
System.out.println("这是一个方法内部类");
}
}
}
public static void main(String[] args) {
Outer outer = new Outer();
outer.out();
//通过外部类的new方法实例化一个对象
Outer.Inner inner = outer.new Inner();
inner.in();
new A().eat();
}
}
//一个Java文件中有多个类但是只能有一个public
class A{
public void eat(){
}
}

View File

@@ -0,0 +1,20 @@
package com.ykl;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}

View File

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB