People say that there are some codes in Java that are mandatory even if the programmer doesn't write them. Java compiler writes it by itself implicitly.
Like my code is this
class Test {
public static void main(String args[]) {
Test obj = new Test();
}
}
I have not written a default constructor here, that means the Java compiler will write it implicitly by itself.
That means my Test.class file has a default constructor in it.
And if I decompile my Test.class file it should look like this
class Test {
Test() {
super();
}
public static void main(String args[]) {
Test obj = new Test();
}
}
Why is it not showing any default constructor in my java file when I'm decompiling?
Your decompiler may not necessarily show a default ctor because it is aware of the implicitness of it. This is a design decision on the part of the implementor of that compiler, and might be configurable with some setting.
However, it's clearly present as bytecode - compiling the following java code:
and then disassembling it with
javap -c A.class
shows a default constructor:Of course, it does nothing but load
this
, push it to the stack, and then invoke the no-arg superclass ctor.