4 ms·
Question that just now occurs to me: what if you have the follow class and invoke it? (typing without an IDE, forgive any compilation errors). I can imagine ans
by hyperpape 4y ago
Question that just now occurs to me: what if you have the follow class and invoke it? (typing without an IDE, forgive any compilation errors). I can imagine answers, but I’m not sure if the JEP explains which one will happen (genuinely unsure, I could’ve easily missed it).
public class Foo {
int x;
public Foo(int x) {
this.x = x;
}
void main() {
System.out.println(x);
}
}
- pron 4y agoThe JEP says: > If a launched class has no static main method but has a non-private zero-parameter constructor ... and a non-private instance main method, then construct an instance of the class... [and] invoke the instance main method Your class doesn't have a zero-parameter constructor nor a suitable static main, so launching it as a program will fail (as it would today).