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 1 year has passed since last update.

*作成中* 継承の多様性について

Posted at
Parent.java
    String val = "A";


    void print() {
        System.out.println(val);
    }

    void difference() {
        System.out.println("super1");
    }

Child.java
    String val = "B";

    void print() {
        System.out.println(val);
    }
    void print2() {
        System.out.println("sub1");
    }


Main.java

package Sample;

public class Main {
    public static void main(String[] args) {
        Parent a = new Parent();
        Parent b = new Child();
        Child c = new Child();

        a.print(); /*親子共通のメソッド*/
        b.print(); /*親子共通のメソッド*/
        c.print2(); /*print2は子クラスで追加したメソッド。子クラスの型で生成しないと動かない*/
        b.difference(); /**/

       }
    }


実行結果

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?