Can you declare the main method as final in Java?
I'll answer
Earn 20 gold coins for an accepted answer.20
Earn 20 gold coins for an accepted answer.
40more
40more
Studied at the University of Johannesburg, Lives in Johannesburg, South Africa.
Sure, it can be declared final! It doesn't matter if it is declared final, the JVM will still find it and run it, and the compiler doesn't care. Yes We can declare main method final. If we make this final it can not be override.Hence we can't use it in its child class.
2023-05-15 12:30:36
评论(499)
Helpful(122)
Helpful
Helpful(2)

Zoe Reed
QuesHub.com delivers expert answers and knowledge to you.
Sure, it can be declared final! It doesn't matter if it is declared final, the JVM will still find it and run it, and the compiler doesn't care. Yes We can declare main method final. If we make this final it can not be override.Hence we can't use it in its child class.