Example & Tutorial understanding programming in easy ways.

Can you declare the main method as final?.

Yes, main can be declared as final. Final means the method or variable cannot be modified in sub-class It does not have any impact on main because Static function is not a part of object instance.

note: final main method cannot be ovreride in sub class.

class father {

public final void moon(Object m) {

System.out.println("Object"); }}

class child extends father {

public void moon(Integer i) {

System.out.println("Int"); }}

public class Test {

public static final void main(String[] args) {        //  main method with final

father f = new father();

child c = new child ();

f.moon (new Integer(0));

c.moon(new Integer(0));


Read More →