Change some files

This commit is contained in:
cyp0633 2021-11-22 18:04:14 +08:00
parent e83ba61eda
commit 1e0d03c92a
9 changed files with 130 additions and 10 deletions

View File

@ -19,6 +19,14 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations-java5</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>

View File

@ -0,0 +1,23 @@
package exceptions;
class OneException1 extends Exception{}
class TwoException1 extends Exception{}
class a1{
public a1() throws OneException1{
}
public void event() throws TwoException1{}
}
public class MyETest1 extends a1{
public MyETest1() throws TwoException1, OneException1 {
super();
}
//public void event()throws OneException1 {} //编译失败
//public void event()throws OneException1,TwoException1 {}//编译失败
public void event()throws TwoException1 {}
}

View File

@ -0,0 +1,28 @@
package exceptions;
class OneException2 extends Exception{}
class TwoException2 extends Exception{}
class ThreeException2 extends Exception{}
class a2{
public a2() throws OneException2{ }
public void event() throws TwoException2{}
}
interface B{
public void event()throws ThreeException2;
public void show() throws ThreeException2;
}
public class MyETest2 extends a2 implements B{
public MyETest2() throws TwoException2, OneException2 {
super();
}
// public void event()throws ThreeException2 {} //编译失败
//public void event()throws TwoException2,ThreeException2 {} //编译失败
//public void event()throws TwoException2 {}//编译失败
public void event(){ }
public void show() throws ThreeException2 { }
}

View File

@ -0,0 +1,23 @@
package exceptions;
class OneException3 extends Exception{}
class TwoException3 extends Exception{}
class ThreeException3 extends TwoException3{}
class a3{
public a3() throws OneException3{
}
public void event() throws TwoException3{}
}
public class MyETest3 extends a3 {
public MyETest3() throws TwoException3, OneException3 {
super();
}
public void event() throws ThreeException3{
}
}

View File

@ -0,0 +1,32 @@
package innerclasses;
import innerclasses.MultiInterfaces1.A1;
import innerclasses.MultiInterfaces1.B1;
public class MultiInterfaces1 {
interface A1 {}
interface B1 {}
static void takesA(A1 a){}
static void takesB(B1 b){}
public static void main(String[] args) {
X1 x = new X1();
Y1 y = new Y1();
//1
takesA(x);
takesA(y);
//2
takesB(x);
takesB(y.makeB());
}
}
class X1 implements A1, B1 {}
class Y1 implements A1 {
B1 makeB() {
return new B1(){};
}
}

View File

@ -1,11 +1,11 @@
//: innerclasses/Parcel10.java
package innerclasses; /* Added by Eclipse.py */
package innerclasses; /* Added by Eclipse.py */
// Using "instance initialization" to perform
// construction on an anonymous inner class.
public class Parcel10 {
public Destination
destination(final String dest, final float price) {
destination(final String dest, final float price) {//final might be omitted
return new Destination() {
private int cost;
// Instance initialization for each object:

View File

@ -1,5 +1,5 @@
//: innerclasses/Sequence.java
package innerclasses; /* Added by Eclipse.py */
package innerclasses; /* Added by Eclipse.py */
// Holds a sequence of Objects.
interface Selector {

View File

@ -1,5 +1,5 @@
//: interfaces/Adventure.java
package interfaces; /* Added by Eclipse.py */
package interfaces; /* Added by Eclipse.py */
// Multiple interfaces.
interface CanFight {
@ -15,13 +15,19 @@ interface CanFly {
}
class ActionCharacter {
public void fight() {}
public void fight() {
System.out.println("ActionCharacter:fight()");
}
}
class Hero extends ActionCharacter
implements CanFight, CanSwim, CanFly {
public void swim() {}
public void fly() {}
public void swim() {
System.out.println("Hero:swim()");
}
public void fly() {
System.out.println("Hero:fly()");
}
}
public class Adventure {

View File

@ -77,11 +77,11 @@ public class NestingInterfaces {
public static void main(String[] args) {
A a = new A();
// Can't access A.D:
//! A.D ad = a.getD();
// A.D ad = a.getD();
// Doesn't return anything but A.D:
//! A.DImp2 di2 = a.getD();
// A.DImp2 di2 = a.getD();
// Cannot access a member of the interface:
//! a.getD().f();
// a.getD().f();
// Only another A can do anything with getD():
A a2 = new A();
a2.receiveD(a.getD());