java抽象类怎么定义对象,能帮我解析下面这段嘛?

[复制链接]
查看11 | 回复3 | 2008-11-11 16:32:39 | 显示全部楼层 |阅读模式
abstract class Contents{abstract public int value();}
interface Destination{String readLabel();}
public class Parcel3{
private class PContents extends Contents{
private int i;
PContents(int cn){i=cn;}
public int value(){return i;}
}
protected class PDestination implements Destination{
private String label;
private PDestination(String whereTo){label=whereTo;}
public String readLabel(){return label;}
}
public Destination dest(String s){return new PDestination(s);}//
public Contents cont(int cn){return new PContents(cn);}//
}
class pl3{
public static void main(String args[]){
Parcel3 p=new Parcel3();
Contents c=p.cont(100);
//
Destination d=p.dest("Tanzania"); // 请问这里是什么意思 啊!!!
System.out.println(c.value());
System.out.println(d.readLabel());
}
}
麻烦帮忙解析下这个程序.特别是带//后面的 !!!!!!!

回复

使用道具 举报

千问 | 2008-11-11 16:32:39 | 显示全部楼层
Parcel3这个类里又两个内部类PContents和PDestination,PContents继承于Contents抽象类,该抽象类有一个int value。PDestination实现了Destination接口,该接口定义了一个String readLabel()方法。pl3类是创建了一个Parcel3对象,Contents c=p.cont(100); 该句调用Parcel3的cont方法创建了一个Parcel3内部类Contents的对象并返回。Destination d=p.dest("Tanzania"); 该句调用Parcel3的dest方法创建了一个PContents对象并返回。这个程序最关键的就是Parcel3类里...
回复

使用道具 举报

千问 | 2008-11-11 16:32:39 | 显示全部楼层
这个结构。。。。明显这程序是考你interface absract class inner class滴Parcel3 p=new Parcel3();Contents c=p.cont(100);Destination d=p.dest("Tanzania"); // p.dest("Tanzania"):Parcel3的一个对象p实例化一个P...
回复

使用道具 举报

千问 | 2008-11-11 16:32:39 | 显示全部楼层
抽象类不能被实例化。但是可以引用子类中的对象。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行