First post code: Parent class Animal class, Subclass Cat Class
Package com.wzy.jpbm.test;
public class Animal {
static{
System.out.println ("Static method of Parent class");
}
{
System.out.println ("construct code block for executing parent class");
}
Public Animal () {
System.out.println ("construct method to execute parent class");
public void A () {
System.out.println ("A method of executing parent class");
}
Package com.wzy.jpbm.test;
public class Cat extends animal{
static{
System.out.println ("static method for Subclasses");
}
{
System.out.println ("Construction code block for executing subclasses");
}
Public Cat () {
System.out.println ("construct method for executing subclasses");
}
@Override public
Void A () {
System.out.println ("a method of executing subclasses");
}
public static void Main (string[] args) {
cat c = new Cat ();
C.A ();
}
Execution results:
static method of the static method subclass of the parent class executes the construction code block of the parent class executes the constructor of the parent class executes the constructor of the subclass execution subclass of
a method