class init & object creation

sponsored links
class init & object creation in inheritance

example:

execute SelfBall.java 's main () function, then get the result.

GrandpaBall.java
/**
 * grandpa ball
 * @author eric
 * @date 2010-3-19  Morning  11:43:42
 */
public class GrandpaBall {
        // static fields
        protected static int gx = gxInit();
        protected static int gy;
        // non-static fields
        protected int ga = gaInit();
        // static block
        static {
                System.out.println("grandpa static block init.");
        }
        // non-static block
        {
                System.out.println("grandpa non-static block init.");
        }

        // constructor
        public GrandpaBall() {
                System.out.println("grandpa constructor execute.");
        }

        private static int gxInit() {
                System.out.println("grandpa static field init.");
                return 1;
        }

        private int gaInit() {
                System.out.println("grandpa non-static field init.");
                return 1;
        }
}


FatherBall.java
/**
 * father ball
 * @author eric
 * @date 2010-3-19  Morning  11:44:01
 */
public class FatherBall extends GrandpaBall {
        // static fields
        protected static int fx = fxInit();
        protected static int fy;
        // non-static fields
        protected int fa = faInit();
        // static block
        static {
                System.out.println("father static block init.");
        }
        // non-static block
        {
                System.out.println("father non-static block init.");
        }

        // constructor
        public FatherBall() {
                System.out.println("father constructor execute.");
        }

        private static int fxInit() {
                System.out.println("father static field init.");
                return 2;
        }

        private int faInit() {
                System.out.println("father non-static field init.");
                return 2;
        }
}


SelfBall.java
/**
 * self ball,test class init & object creation
 * @author eric
 * @date 2010-3-19  Morning  11:44:19
 */
public class SelfBall extends FatherBall {
        // static fields
        protected static int sx = sxInit();
        protected static int sy;
        // non-static fields
        protected int sa = saInit();
        // static block
        static {
                System.out.println("self static block init.");
        }
        // non-static block
        {
                System.out.println("self non-static block init.");
        }

        // constructor
        public SelfBall() {
                System.out.println("self constructor execute.");
        }

        private static int sxInit() {
                System.out.println("self static field init.");
                return 3;
        }

        private int saInit() {
                System.out.println("self non-static field init.");
                return 3;
        }

        // main
        public static void main(String[] args) {
                System.out.println();
                System.out.println("executeing main() ... class has been loaded.");
                System.out.println("object is going to be created:");
                System.out.println();
                // create object
                SelfBall sb1 = new SelfBall();
                System.out.println();
                System.out.println("object created.");
        }
}
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of class init & object creation

  • IBM Ajax Tutorial Series

    Links: http://ibm.csdn.net/ISN_J.aspx?action=JMP&pointid=1550 Part 10: Using JSON for data transmission In the asynchronous application to send and receive information, you can choose to plain text and XML as data format. Ajax grasp of this issue ...

  • jquery ajax example

    1. Check js file $. ajax (( type: "GET", url: "test.js", dataType: "script" )) 2.post data $. ajax (( type: "POST", url: "xxxx", data: "name = zhaoaiqing & age = 25", success: function ( ...

  • Unable to load bean: type: struts-derfault.xml abnormal

    Struts2 in the use of a lot of friends from time to time we encountered this anomaly, leading to its main reason is because the wrong package, we have to be xwork-2.1.1.jar and struts2-core-2.1.2.jar, replaced xwork-2.0. 4.jar and struts2-core-2.0.14.jar

  • Javascript Object Model

    Javascript Object Model

  • Strength of live practice teaching materials, suitable for each person team look - UFIDA Hua Table CTO talk about "out of the software factory"

    A few months ago, on reading "Going the software factory," one book, not yet published at that time, it can be considered the reference of the watch. Although the language rather uneventful, but the contents of people really can not but carry on

  • Workspace run under different Eclipse

    Now do live more and more often required to use eclipse in java and ruby & rails project conducted between the tangential shear from the past, because in the rails project used a coloring Aptana preferences, the results open the java project sour ...

  • Software development sunflower Baodian [reprint]

    Master the ability to reuse code very familiar with the new API's fast. This is because, he once used a lot of the API, have a lot of reusable code. He knows what is available and what is deficient. He has been using Qt, also used by gtk +, also used

  • spring + hibernate + oracle9i to read and write CLOB

    Database-driven update classes12-9i.jar Hibernate modify the configuration of the following code <bean/> <bean Lazy-init="true"> <property name="nativeJdbcExtractor"> <ref local="nativejdbcExtractor"/>

  • can not be represented as java.sql.Timestamp

    Development of procedures for the use of hibernate when, some time there is no need to fill in the fields, but after the hibernate query time reported "Java.sql.SQLException: Value'0000-00-00 'can not be represented as java.sql.Timestamp ...

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries