Java Inheritance - calling superclass method
You can do:
super.alphaMethod1();
Note, that super
is a reference to the parent class, but super()
is its constructor.
You can't call alpha's alphaMethod1() by using beta's object But you have two solutions:
solution 1: call alpha's alphaMethod1()
from beta's alphaMethod1()
class Beta extends Alpha{ public void alphaMethod1() { super.alphaMethod1(); }}
or from any other method of Beta like:
class Beta extends Alpha{ public void foo() { super.alphaMethod1(); }}class Test extends Beta { public static void main(String[] args) { Beta beta = new Beta(); beta.foo(); }}
solution 2: create alpha's object and call alpha's alphaMethod1()
class Test extends Beta{ public static void main(String[] args) { Alpha alpha = new Alpha(); alpha.alphaMethod1(); }}