- class ExtendA
- {
- private int num=1;
- public void setNum(int num)
- {
- this.num=num;
- }
- public int getNum()
- {
- return num;
- }
- public void showA()
- {
- System.out.println("A");
- }
- }
- class ExtendB extends ExtendA
- {
- public void showB()
- {
- System.out.println("B");
- }
- }
- class Demo
- {
- public static void main(String[] args)
- {
- ExtendB e=new ExtendB();
- e.showA();
- e.showB();
- e.setNum(5);
- System.out.println(e.getNum());
- }
- }
复制代码 |