-1

I am revisiting the concepts of java. So, I am looking in this example

 class A {
    A( ) {System.out.print("CA");}
    static {System.out.print("SA");}
}
class B extends  A {
    B() {System.out.print("CB");}
    static {System.out.print("SB");}
    public static void main(String[] args) {
        B b = new B();
    }
}

output here is SASBCACB

So I didn't understand why CA message is printed since class A constructor is not called.

My question is kind of basic java but its better to know things rather blank about it.

1
  • 1
    The constructor in B implicitly calls super() which is A's constructor Commented Apr 26, 2017 at 13:24

1 Answer 1

1

A is instantiated when you create a B, that is how inheritance works.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.