美文网首页
继承泛型类和泛型接口学习02

继承泛型类和泛型接口学习02

作者: 哈迪斯Java | 来源:发表于2021-11-26 10:12 被阅读0次

    package All.D13.Generic_;

    public class Demon04 {
    public static void main(String[] args) {
    Teacher<Integer,String>f=new Student<>(123,"jack");
    System.out.println("===========");
    Student<Integer,String,Boolean>s=new Student<>(213,true);
    }
    }
    class Teacher<T1,T2>{
    T1 t1;
    T2 t2;

    public Teacher(T1 t1, T2 t2) {
        this.t1 = t1;
        this.t2 = t2;
        System.out.println("t1的类型为"+this.t1.getClass());
        System.out.println("t2的类型为"+this.t2.getClass());
    }
    

    }
    class Student<T1,T2,T3> extends Teacher<T1,T3>{
    public Student(T1 t1, T3 t2) {
    super(t1, t2);
    }
    }
    ===========
    t1的类型为class java.lang.Integer
    t2的类型为class java.lang.String
    ===========
    t1的类型为class java.lang.Integer
    t2的类型为class java.lang.Boolean


    image.png

    package All.D13.Generic_;

    public class Demon04 {
    public static void main(String[] args) {
    Teacher<Integer,String>f=new Student<>(123,"jack");
    System.out.println("===========");
    Student<Integer,String,Double>s=new Student<>(213,"qwe");
    }
    }
    class Teacher<T1,T2>{
    T1 t1;
    T2 t2;

    public Teacher(T1 t1, T2 t2) {
        this.t1 = t1;
        this.t2 = t2;
        System.out.println("t1的类型为"+this.t1.getClass());
        System.out.println("t2的类型为"+this.t2.getClass());
    }
    

    }
    class Student<T1,T2,T3> extends Teacher<T1,String>{
    public Student(T1 t1, String t2) {
    super(t1, t2);
    }
    }

    image.png

    package All.D13.Generic_;

    public class Demon04 {
    public static void main(String[] args) {
    Teacher<Integer,String>f=new Student<>(123,"jack");
    System.out.println("===========");
    Student<Integer,String,Double>s=new Student<>(213,"qwe");
    }
    }
    class Teacher<T1,T2>{
    T1 t1;
    T2 t2;

    public Teacher(T1 t1, T2 t2) {
        this.t1 = t1;
        this.t2 = t2;
        System.out.println("t1的类型为"+this.t1.getClass());
        System.out.println("t2的类型为"+this.t2.getClass());
    }
    

    }
    class Student<T1,T2,T3> extends Teacher<Integer,String>{
    public Student(Integer t1, String t2) {
    super(t1, t2);
    }
    }
    ==========


    image.png

    相关文章

      网友评论

          本文标题:继承泛型类和泛型接口学习02

          本文链接:https://www.haomeiwen.com/subject/rygatrtx.html