0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JAVA 練習問題13-3答え(P527)

Posted at

■A.java

//宣言時にfinalが付いているクラスは継承できない
public final class A extends Y {
	public void a() {
		System.out.print("Aa");
	}

	public void b() {
		System.out.print("Ab");

	}

	public void c() {
		System.out.print("Ac");
	}

}

B.java

```java

public class B extends Y {
	public void a() {
		System.out.print("Ba");

	}

	public void b() {
		System.out.print("Bb");
	}

	public void c() {
		System.out.print("Bc");
	}

}

■X.java


public interface X {
	void a();

}

■Y.java

public abstract class Y implements X {
	public abstract void a();
	public abstract void b();

}

■Main23.java

public class Main23 {
	public static void main(String[] args) {

		X obj = new A();

		//練習 13-3
		A obj1 = new A();
		B obj2 = new B();

		Y[] objj = new Y[2];
		objj[0] = new A();
		objj[1] = new B();

		for(Y temporaryVariable : objj) {
			temporaryVariable.b();
		}
	}
}

■実行結果
AbBb

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?