一个内部类的使用,学到了一些东西...

abstract class Contents
{
 abstract public int value();
}
interface Destination
{
 String readLabel();
}

public class Parcel3
{
 private class PContents extends Contents//此内部类由抽象类Contents所派生
 {
  private int i;
  PContents(int cn){i=cn;}
  public int value(){return i;}
 }
 protected class PDestination implements Destination//此内部类实现了接口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());
 }
}

 

今天才知道编译时和执行时可以不是同一个类,,

就拿这个例子来说,编译应是javac Parcel3.java

执行时而是:java pl3

 

搞了半天才搞明白....!!!!!!!!!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值