If I have an inner class, like this:
public class Test
{
public class Inner
{
// code ...
}
public static void main(String[] args)
{
// code ...
}
}
When I compile it, I expect it should generate two files:
Test.class
Test$Inner.class
So why do I sometimes see classfiles like SomeClass$1.class, even though SomeClass does not contain an inner class called "1"?
Explanation : The java compiler creates two class files in case of inner class.
class" files are created in the corresponding folder as there are four classes are defined in the "ClassTest. java" file. Those are A. class, B.
For Compiling: After compilation there will be 3 class files in corresponding folder named as: Sample. class.
There are basically four types of inner classes in java.
The SomeClass$1.class represent anonymous inner class
hava a look at the anonymous inner class section here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With