Hello everyone,
I have another question, given that:
° file name could be anything if there is no public class defined in such file
° file name has to be the same of the public class IF there is one
° could be more than one class with a main method in same file
I tried to run a file with 3 classes and within 2 of them was a main method.
File name is completely different from the 3 cointained classes.
Compiles fine, JVM runs fine, but...
How can the JVM know which class to run if there are 2 main methods present?
I tried also to change the appereance order of the classes, but JVM run always the same class.
Code: Select all
class A{
final int fi = 10;
}
class C {
public static void main(String[] args) {
System.out.println("inside C class");
}
}
class B extends A{
int fi = 15;
public static void main(String[] args){
B b = new B();
b.fi = 20;
System.out.println(b.fi);
System.out.println(((A)b).fi);
}
}
It prints
always the statements in class B.
File's name is : Base.java
Why?
Any help would be greately appreciated.