File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

It is Strange about main method

 
Krishna Latha Grandhi
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


if we try to execute the above code with
main(java.lang.String[]) in Tester cannot override main(java.lang.String[]) in TestEx1;

This output is correct. ok.

But if we commented the main method in Tester class the super class method is gets executed. without inheriting the method how can that main method gets executed.

Please clarify my doubt..

Regards,
Krishna.
 
Naresh Gunda
Ranch Hand
Posts: 163
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final methods can be inherited.
final methods can't be overridden.
static methods can be inherited.

When u execuate a program, JVM looks for main method. It is not defined in Tester class, but inherited from super class.

Regards
Naresh
[ December 21, 2005: Message edited by: Naresh Kumar ]
 
Krishna Latha Grandhi
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final methods can be inherited.
final methods can't be overridden.
static methods can be inherited.

Hey, I know the above things...
But I have a doubt that how the final method of TestEx1 class gets invoked from Tester class...
But You contradicted your assumptions...

When u execuate a program, JVM looks for main method. It is not defined in Tester class, but inherited from super class.


Plz any one Explain.....

Regards,
Krishna.
 
Hemant Agarwal
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM will look for the main method in that class or any of it's superclass. If it found the main method inside the class it is calling then it will not look into the superclass otherwise it will look out for main method inside all of it's super classes starting from that class. If it found, then the compiler will not give errors.
 
Krishna Latha Grandhi
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Hemanth

Regards,
Krishna
 
Sachin Dimble
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hari do u agree with these-
final methods can be inherited.
final methods can't be overridden.
static methods can be inherited.

if yes then it's simple u are inheriting static main of TestExe1 into Tester that means now ur Tester has also a main method(it's own though inherited) & same is executing!!!
Hope u understand!

With Best Regards,
Sachin.
 
vipul patel
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main method in the child class is just hiding the one defined in the parent class.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic