用java内部类实现多重继承

package test; /** * class one: Class1 * @author TJ */ public class Class1 { /** * method: getName * @return name */ public String getName() { return "Luck"; } }  

package test; /** * class two: Class2 * @author TJ */ public class Class2 { /** * method: getAge * @return age */ public int getAge() { return 25; } } 

package test; public class MainClass { /** * inner class one: Test1 extends Class1 * @author TJ */ public static class Test1 extends Class1 { @Override public String getName() { return super.getName(); } } /** * inner class two: Test2 extends Class2 * @author TJ */ public static class Test2 extends Class2 { @Override public int getAge() { return super.getAge(); } } /** * method: showName * @return name */ public String showName() { return new Test1().getName(); } /** * method: showAge * @return age */ public int showAge() { return new Test2().getAge(); } public static void main(String args[]) { MainClass example = new MainClass(); System.out.println("name:" + example.showName()); System.out.println("age:" + example.showAge()); } }  

 

原文地址http://topic.csdn.net/u/20100312/10/822b0e94-8d2f-4bf0-9746-3424eaea40ce.html?10780

你可能感兴趣的:(java,String,Class,2010)