Objective-c中@interface、@implementation、@protocal

來源:互聯網
上載者:User

標籤:

以下

  •     void print();  
  • };  
  • class AC{  
  • };  
  • 這時候,AI和AC是獨立存在,AC不會因為沒有和AI建立關係而編譯錯誤,將AC做以下修改後,AI才和AC建立了關係,AC必須實現AI中聲明的方法才能通過編譯。

    [html] view plaincopyprint?
    1. class AC implement AI{  
    2.     void print(){  
    3.         system.out.println(‘Hello World‘);  
    4.     }  
    5. };  

    現在,我們來看<Foundation/Foundation.h>  
  •   
  •   
  • @protocol A  
  • @end  
  •   
  •   
  • <strong style="color:white;background-color:#880000">@interface</strong> A : NSObject<A>  
  • -(void) test:(id<A>) obj;  
  • @end  

  • 注意這裡的 -(void) test:(id<A>) obj; 這表明test方法接受一個任意類型的對象做為參數,但是該參數對象必須實現介面A,類似於java中的

    void test(List<A> obj) 。

 

Objective-c中@interface、@implementation、@protocal

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.