• 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

Method decleration in the main()?

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will happen when you attempt to compile and run this code?

public class Mod{
public static void main(String argv[]){
}
public static native void amethod();

}

1) Error at compilation: native method cannot be static
2) Error at compilation native method must return value
3) Compilation but error at run time unless you have made code containing native amethod available
4) Compilation and execution without error.


Now the problem is when i am compiling this code,an error is generated by the name "Illegal start of expression"...
But this option is not given in the Question's answer options....

Another doubt is that whether a function can be declared in the main?
As far as i know, a function should not be defined in the main but it can be called in the main only...

So, Please.... justify this question...

Thanks..

this code is the 7th question in the following link..

http://www.jchq.net/mockexams/exam2.htm
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now the problem is when i am compiling this code,an error is generated by the name "Illegal start of expression"...
But this option is not given in the Question's answer options....


That is most likely because you made a typing error. I copied and pasted your code above in a file Mod.java and it compiled without errors.

Another doubt is that whether a function can be declared in the main?
As far as i know, a function should not be defined in the main but it can be called in the main only...


What do you mean by "in the main" - inside the main(...) method? No, you cannot define methods inside other methods, but that's not what your code is doing. There is a closing } before the declaration of amethod(), so it's not inside the main(...) method.
[ May 02, 2007: Message edited by: Jesper Young ]
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic