java内部类的试验

  1. package innertest;
  2. interface product{
  3.    void price();
  4. }
  5. public class test1 {
  6.  private int i=1;
  7.  private String ts="test1";
  8.     private class shoe implements product{
  9.        public void price(){
  10.         System.out.println("i am excuted at "+ts+" innerclass!");
  11.         test();//内部类可以访问类的成员和方法
  12.        }
  13.     }
  14.     public shoe getshoe(){
  15.      return new shoe();
  16.     }
  17.     private void test(){
  18.      System.out.println(i);
  19.     }
  20.     public static void main(String[] args){
  21.      test1 t=new test1();
  22.      product p=t.getshoe();
  23.         test1.shoe s=t.new shoe();
  24.         s.price();
  25.      p.price();
  26.      
  27.      
  28.     }
  29. }
  30. 使用内部类,可以完全隐藏实现细节。某个类的内部类和其成员,方法具有同等的权利
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值