Solution class extends C, i know, I just deleted the inheritance so I can verify the code so it shows here.
Anyway, I solved the problem but I don't understand the following:
1. How is CCB printed considering that nothing from C class is called.
Is it because when a Solution class object is created, a Solution C class default constructor is called as well?
Even so, the output shouldn't it be 'CBAYS' ?
Where is the second 'C' coming from? Is it coming from JustAnInterface interface which has a B class that extends class C so, when B class is called from the Solution C class default constructor 'C' is printed for a second time and then followed by 'B' ?
package com.codegym.task.task24.task2411;
/*
Let's recall inheritance
*/
public class Solution {
private class A {
protected String value = "A";
public A() {
System.out.print(value);
}
}
private A a = new A() {
{ // Anonymous classes don't have their own constructors, but you can do something in the class's initialization block
value = "Y";
if (super.getClass().getName().contains(".Solution$")) {
System.out.print(value);
}
}
};
public Solution() {
System.out.print("S");
}
public static void main(String[] args) {
new Solution();
}
}