Hi there.
I have placed 1 public and 1 default class in a file. The name matches the public class name.
class OtherClass{
public static void main(
String[] args){
System.out.println("Inside OtherClass main");
}
}
public class ClassTester{
public static void main (String[] args) {
System.out.println("Inside ClassTester main");
}
}
I had intended for the JVM to execute the public class and not the default "OtherClass".
It appears that the JVM will just execute the whichever class comes first, in this case, the "OtherClass".
How do I make it execute the main in ClassTester first, without moving ClassTester on top of "OtherClass".
_________________________
BTW
If you are wondering why, I was writing exceptions within one source code file and thought that the public class would be executed first:
class AnotherException{
public static void main(String[] args){
System.out.println("Another Exception thrown");
}
}
class MyExceptionThree extends MyExceptionTwo{
public static void main(String[] args){
System.out.println("Exception 3 thrown");
}
}
class MyExceptionTwo extends MyExceptionOne{
public static void main(String[] args){
System.out.println("Exception 2 thrown");
}
}
class MyExceptionOne extends Exception{
public static void main(String[] args){
System.out.println("Exception 1 thrown.");
}
}
public class TestMyExceptions{
public static void main(String[] args) throws MyExceptionTwo, IOException
{
TestMyExceptions tester1 = new TestMyExceptions();
// Code that will cause some of my exceptions to be thrown
}
}