Skip to content

Commit

Permalink
JavaSE9作业和JavaSE10代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunbeam-5 committed Sep 13, 2022
1 parent 82ed53e commit a9cd582
Show file tree
Hide file tree
Showing 21 changed files with 292 additions and 0 deletions.
3 changes: 3 additions & 0 deletions JavaSE10/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions JavaSE10/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions JavaSE10/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions JavaSE10/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions JavaSE10/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions JavaSE10/JavaSE10.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file added JavaSE10/out/production/JavaSE10/demo1/Alpha.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/demo1/Base.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/demo2/Base.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/demo2/Derived.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/demo3/X.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/demo3/Y.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/demo3/Z.class
Binary file not shown.
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/多态/Bird.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/多态/Dog.class
Binary file not shown.
Binary file added JavaSE10/out/production/JavaSE10/多态/Test.class
Binary file not shown.
16 changes: 16 additions & 0 deletions JavaSE10/src/demo1/Alpha.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package demo1;

class Base {
Base() {
System.out.print("Base");
}
}

public class Alpha extends Base {

public static void main( String[] args ) {
new Alpha();//1
//调用父类无参的构造方法
new Base();//2
}
}
17 changes: 17 additions & 0 deletions JavaSE10/src/demo2/Derived.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package demo2;

class Base{
public Base(){
System.out.print("B");
}
}

public class Derived extends Base{
public Derived (String s) {
super();
System.out.print("D");
}
public static void main(String[] args){
new Derived("C");
}
}
22 changes: 22 additions & 0 deletions JavaSE10/src/demo3/Z.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package demo3;

class X{
Y y=new Y();//1
public X(){//2
System.out.print("X");
}
}
class Y{
public Y(){//3
System.out.print("Y");
}
}
public class Z extends X{
Y y=new Y();//4
public Z(){//5
System.out.print("Z");
}
public static void main(String[] args) {
new Z();
}
}
79 changes: 79 additions & 0 deletions JavaSE10/src/多态/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package 多态;

class Animal{
private String name;
private int age;

public Animal(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public void eat(){
System.out.println(name + "正在吃饭");
}

@Override
public String toString() {
return "Animal{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
class Dog extends Animal{

public Dog(String name, int age) {
super(name, age);
}
public void bark(){
System.out.println(getName()+"汪汪汪!");
}
}
class Bird extends Animal{
public String wing;
public Bird(String name, int age) {
super(name, age);
}
public void fly(){
System.out.println(getName()+"正在飞");
}
public void eat(){
System.out.println(getName()+"要吃鸟粮");
}
}

public class Test {
public static void main(String[] args) {
/*Bird bird = new Bird("鹦鹉", 2);
Animal animal = bird;*/
//上下两段相等
Animal animal = new Bird("鹦鹉", 2);//向上转型
/*animal.fly();*///只能引用Animal里面的方法
/*animal.wing;*///只能调用自己特有的方法,不可以调用子类的方法
animal.eat();//动态绑定
}

public static void main1(String[] args) {
Bird bird = new Bird("鹦鹉",2);
bird.fly();
bird.eat();

}
}

0 comments on commit a9cd582

Please sign in to comment.