public class FanXintTest<T> { private T frunt; public FanXintTest(T frunt){ this.frunt=frunt; } public T getFrunt(){ return frunt; } public static void main(String[] args) { Frunt frunt=new Frunt(); frunt.name="水果"; frunt.weight="1kg"; FanXintTest<Frunt> fxt=new FanXintTest<Frunt>(frunt); Frunt frunt2=fxt.getFrunt(); System.out.println(frunt2.name); Apple apple=new Apple(); apple.name="苹果"; apple.color="red"; FanXintTest<Apple> afxt=new FanXintTest<Apple>(apple); System.out.println(afxt.getFrunt().name); } } class Frunt{ public String name; public String weight; } class Apple extends Frunt{ public String color; }
时间: 2025-01-04 16:51:50