示例代码:采用昨天“那些人之一”问题中的代码
D:\中,- package pack;
- import mydemo.*;
- class Packagedemo
- {
- public static void main(String[] args)
- {
- mydemo.DemoA d=new mydemo.DemoA();
- d.show();
- packo.Demo b= new packo.Demo();
- b.method();
- System.out.println("Hello Package!");
- }
- }
复制代码
E:\中- package mydemo;
- public class DemoA extends packo.Demo
- {
- public void show()
- {
- method();
- System.out.println("DemoA show run");
- }
- }
复制代码
F:\中- package packo;
- public class Demo
- {
- public /*protected 保护*/ void method()
- {
- System.out.println("Demo method run");
- }
- }
复制代码
编译运行: |
|