d.java

来自「Java 入门书的源码」· Java 代码 · 共 32 行

JAVA
32
字号
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

/* Class D extends A but is not in the same package. 
 * D can't use d2, get2(), or the class B which are 
 * visible only in package visibility. D can use d3 
 * and getd3(), but only from an object of type D, not 
 * from an object of type A.  Class E can only use
 * public data and methods. 
 */

import visibility.*;
public class D extends A {
  public static void main(String [] args) {
    A a = new A();
    D d = new D();
    int i,j;
    i = a.d1 + d.d3 + a.usePrivate();
    j = a.get1() + d.get3();
    System.out.println("i is " + i + " and j is " + j);
  }
}
class E {
  public static void main(String [] args) {
    A a = new A();
    D d = new D();  
    int i,j;
    i = a.d1 + d.usePrivate();
    j = d.get1();
    System.out.println("i is " + i + " and j is " + j);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?