乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      接口和抽象類的定義方式舉例說明

       鳳舞天煌 2007-05-30
      接口定義
      關(guān)于java的接口定義方式,以下三種情況下可以采用接口定義方式:
      1.    接口中聲明的變量全部為final 和static類型的,并且這個(gè)接口的作用在于定義一些值不能改變的變量。
      舉個(gè)例子:
      public interface ObjectConstants{
      public static final String SPACE = new String(" ");
      public static final char FORMFEED = ‘\f‘;
      }
      2.    接口中只定義可供實(shí)現(xiàn)的抽象方法
      EventListener.java
          public interface EventListener {
          public void handleEvent(Event evt);
          }
      Runnable.java
      package java.lang;
          public interface Runnable {   
          public abstract void run();
          }
      3.    還有一種方式是上述兩種方式的組合,如非必要一般會將這樣一個(gè)接口定義拆分成兩個(gè)接口定義
      抽象類的定義
      1.    如果一個(gè)類包含一個(gè)接口但是不完全實(shí)現(xiàn)接口定義的方法,那么該類必須定義成abstract型
      例如InputStream.java類的定義方式:
      package java.io;
      public abstract class InputStream implements Closeable {
          // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
          private static final int SKIP_BUFFER_SIZE = 2048;
          // skipBuffer is initialized in skip(long), if needed.
          private static byte[] skipBuffer;   
          public abstract int read() throws IOException;

         
          public int read(byte b[]) throws IOException {
          return read(b, 0, b.length);
          }   
          public int read(byte b[], int off, int len) throws IOException {
          if (b == null) {
              throw new NullPointerException();
          } else if ((off < 0) || (off > b.length) || (len < 0) ||
                 ((off + len) > b.length) || ((off + len) < 0)) {
              throw new IndexOutOfBoundsException();
          } else if (len == 0) {
              return 0;
          }
          int c = read();
          if (c == -1) {
              return -1;
          }
          b[off] = (byte)c;
          int i = 1;
          try {
              for (; i < len ; i++) {
              c = read();
              if (c == -1) {
                  break;
              }
              if (b != null) {
                  b[off + i] = (byte)c;
              }
              }
          } catch (IOException ee) {
          }
          return i;
          }
       public long skip(long n) throws IOException {
          long remaining = n;
          int nr;
          if (skipBuffer == null)
              skipBuffer = new byte[SKIP_BUFFER_SIZE];
          byte[] localSkipBuffer = skipBuffer;        
          if (n <= 0) {
              return 0;
          }
          while (remaining > 0) {
              nr = read(localSkipBuffer, 0,
                    (int) Math.min(SKIP_BUFFER_SIZE, remaining));
              if (nr < 0) {
              break;
              }
         remaining -= nr;
          }    
          return n - remaining;
          } 
          public int available() throws IOException {
          return 0;
          }   
          public void close() throws IOException {}  
          public synchronized void mark(int readlimit) {}    
          public synchronized void reset() throws IOException {
          throw new IOException("mark/reset not supported");
          }
          public boolean markSupported() {
          return false;
          }
      }
      2.    抽象類的方法體中只定義抽象的方法,例如AbstractMethodError.java
          package java.lang;
          public class AbstractMethodError extends IncompatibleClassChangeError {
          public AbstractMethodError() {
          super();}
          public AbstractMethodError(String s) {
          super(s); }
      }

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多