java - Why does javac create <init> method in class that doesn't create any instance -
i have question related java compiler.
example code:
public class theclass { public static void main(string[] args) { system.out.println("hello world!"); } }
when compile class can see in javaclassviewer, class contains <init>
method invokes java.lang.object
construcotr, not creating instance of class , no constructor called. jvm calls static method main, doesn't create instance of class. so, why compiler produces
<init>
method? understand if create object of theclass
the jls requires default constructor generated:
8.8.9. default constructor
if class contains no constructor declarations, default constructor implicitly declared.
also:
i not creating instance of class
irrelevant. compiler can't know that.
Comments
Post a Comment