-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |