• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why it is giving me this compile time error ?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



according to me static method main() should hide the instance method from the dodo class. what is the reason the compiler gives error when i try to override the instance method with static method ?
 
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, you can't have two main method, and i have another doubt, how is it possible to override instance method with class method ?
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:what is the reason the compiler gives error when i try to override the instance method with static method ?


You cannot hide an instance method by marking it as static in the child class. You can only override instance methods.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saloni jhanwar wrote:I think, you can't have two main method


You can't have two methods with the same signature. Note that both the main method have different signatures and the compiler is pointing out error when you try to hide an instance method.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks john . would like to sum up so that there is no confusion.

we cannot hide an instance method with a static method . secondly you can have two methods with the same name but their signatures should be different, which means there argument list much be of different number and or type. that is just plain overloading. you can't define methods which is already defined in the class.
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:thanks john . would like to sum up so that there is no confusion.

we cannot hide an instance method with a static method . secondly you can have two methods with the same name but their signatures should be different, which means there argument list much be of different number and or type. that is just plain overloading. you can't define methods which is already defined in the class.



Yes, now you are right.You can have two or more methods with same name even main method but you have to overload them.
 
reply
    Bookmark Topic Watch Topic
  • New Topic