This week's book giveaway is in the Java in General forum.
We're giving away four copies of Java by Comparison (eBook) and have Simon Harrer, Jörg Lenhard, Linus Dietz on-line!
See this thread for details.
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I have got two conclusion from above code is that  RSS feed

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Can we declare a method in main(String...args) method like this-----


class a
{
public static void main(String...args)
{
static void method()
{//some code here
}

System.out.println(method());
}
}




I have got two conclusion from above code is that
1.We can not define a method in main() method
2.We can not call a method in println statement that has a return type void.It means method () must return something.

Am i right?
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes your understand this. In fact it is not possible to nested method(a method within method).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!