In Java, how do I call a base class's method from the overriding method in a derived class?

后端 未结 12 887
無奈伤痛
無奈伤痛 2020-11-27 02:50

I have two Java classes: B, which extends another class A, as follows :

class A {
    public void myMethod() { /* ... */ }
}

class B extends A {
    public          


        
12条回答
  •  有刺的猬
    2020-11-27 03:06

    // Using super keyword access parent class variable
    class test {
        int is,xs;
    
        test(int i,int x) {
            is=i;
            xs=x;
            System.out.println("super class:");
        }
    }
    
    class demo extends test {
        int z;
    
        demo(int i,int x,int y) {
            super(i,x);
            z=y;
            System.out.println("re:"+is);
            System.out.println("re:"+xs);
            System.out.println("re:"+z);
        }
    }
    
    class free{
        public static void main(String ar[]){
            demo d=new demo(4,5,6);
        }
    }
    

提交回复
热议问题