Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android 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).
 
Don't listen to Steve. Just read this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!