If a class has inheritance in a Java program, do I need to put main method in the superclass or subclass? Many programs put the main method in different positions. Can anybody tell me how to do that? Thanks a lot!
I think it might be best to have a simple class whose sole dedicated purpose is to contain the static main method. It simple and clear.
Your main method would then get things started by creating the initial objects from your program.
You could create a new dedicated class, let's say Launcher, with a main method, instantiate your classes there, and manage any unexpected exceptions:
public class Luncher{
public static void main(String args){
//insert argument checking logic
try{
new MyClass.executeLogic(someArguments);
}catch(Exception e){
//insert exception handling logic here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With