java吧 关注:1,225,722贴子:12,684,685
  • 2回复贴,共1

求助啊!!!T_T 求大神指出错误啊,小弟感激不尽。

只看楼主收藏回复

ckage 实验;
abstract class Bred {
String name; public void speakName() {
System.out.println("这是一只 " + this.name);
} public void math() {
}; public String toString() {
return name;
}
}class FengHuang extends Bred {
final String name = "凤凰"; public void math() {
System.out.println("他会做算术");
}
}class Psittaciformes extends Bred {
final String name = "鹦鹉"; public void math() {
System.out.println("他会做算术");
}
}class MaQue extends Bred {
final String name = "麻雀"; public void math() {
System.out.println("他不会做算术");
}
}class Work { public static Bred getAdd(String name) {// throws Exception {
Bred aa = null;
// try {
if ("凤凰".equals(name)) {
aa = new FengHuang();
}
if ("鹦鹉".equals(name)) {
aa = new Psittaciformes();
}
if ("麻雀".equals(name)) {
aa = new MaQue();
}
// } catch (Exception e) {
// System.out.println(e);
// }
return aa;
}
}public class WorkGround {
public static void main(String[] args) {
//Bred a=null;
Work w=new Work();
System.out.println(w.getAdd("凤凰"));
}
}
执行结果为 null
为什么啊,求指教


IP属地:上海1楼2013-03-05 19:14回复


    2楼2013-03-05 19:21
    回复
      楼上无节操


      3楼2013-03-05 19:22
      回复