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 →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!