zoukankan      html  css  js  c++  java
  • java_类泛型承继方法

    package ming;
    
    class Apple3<T>{
    	private T info;
    	public Apple3(){}
    	public Apple3(T info){
    		this.info = info;
    	}
    	public T getInfo() {
    		return info;
    	}
    	public void setInfo(T info) {
    		this.info = info;
    	}
    	
    }
    
    class A1 extends Apple3<String>{
    	public A1(){}
    	public A1(String info){
    		super(info);
    	}
    	public String getInfo(){
    		return "子类"+super.getInfo();
    	}
    }
    
    
    class A2 extends Apple3{
    	public A2(String info){
    		super(info);
    	}
    	public String getInfo(){
    		return super.getInfo().toString();
    	}
    }
    
    public class Apple3Test {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Apple3<String> base3 = new Apple3<String>("apple");
    		A1 a1 = new A1("apple");
    		A2 a2 = new A2("apple");
    		System.out.println(base3.getInfo());
    		System.out.println(a1.getInfo());
    		System.out.println(a2.getInfo());
    	}
    
    }
    

    //A1,A2 为方法1和方法2

    //泛型不能有static

  • 相关阅读:
    今天又能去健身了
    今天招受情感打击
    js实现菜单命令
    爱好者
    杂七杂八
    wu
    后缀数组学习笔记——罗穗骞倍增算法代码
    POJ 3261 Milk Patterns
    URAL 1158 Censored!
    POJ 1743 Musical Theme
  • 原文地址:https://www.cnblogs.com/MarchThree/p/3720462.html
Copyright © 2011-2022 走看看