Class initialization and object initialization

xiaoxiao2021-03-06  40

? What's the output / ** * @author 031202 * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / class Parent {class InnerClass {public InnerClass () { System.out.println ( "Construct parent's inner class");}} static class StaticInner {public StaticInner () {System.out.println ( "Construct parent's StaticInner class");}} private InnerClass i = new InnerClass (); Private static staticinner s = new staticinner (); public parent () {system.out.println ("construct parent");}

}

public class Child extends Parent {class InnerClass {public InnerClass () {System.out.println ( "Construct child's inner class");}} static class StaticInner {public StaticInner () {System.out.println ( "Construct child's StaticInner class ");}} Private static staticinner s = new staticinner (); private innerclass i = new innerclass (); public child () {system.out.println (" construct child ");} public static void main (String [] args) {new Child ();}} answer: Construct parent's StaticInner classConstruct child's StaticInner classConstruct parent's inner classConstruct ParentConstruct child's inner classConstruct Child

Do you really understandnand the class initialization?

转载请注明原文地址:https://www.9cbs.com/read-63165.html

New Post(0)