Abstract_super_constructor.htm |
Below is an example of using super() key word to call super class from a
constructor of extended class. |

|
In this example the object from the last generation was initiated to
call the constructor, as a result the constructor from the top of the chain
of classes was activated, then descended to the next level, as shown in the
picture. |
Example code
import java.io.*;
public class Test_This {
public static void main(String[] args) throws IOException{
A aa = new A();
}
}
class Process extends Abs_class
{
public Process(){ super(); System.out.println("constructor of Process :");
}
public int n1 =12; String name = "default\t";//defined and instantiated a
filed
public String method_function(String str)
//abstract method must be implemented
{ name += str.toUpperCase();
System.out.print("Welcome from 1: " + str);
return name;
}
}
class A extends Process
{
public A() { super();
System.out.println("constructor of A :");
//super();//not allowed
}
}
abstract class Abs_class
{
public Abs_class(){System.out.println("constructor of Abstract Class :");
}
abstract String method_function(String str);
}
|
 |
|
|
|
|
|