| Author |
why not we define a static member function inside a main
|
abhinav sood
Greenhorn
Joined: Aug 05, 2011
Posts: 9
|
|
class emp
{
static String cname="Abhinav";
public static void main(String... s)
{
static void display()
{
System.out.println(cname)
}
}
}
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56230
|
|
|
Because a method cannot be defined within another method.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Alex Armenteros
Ranch Hand
Joined: May 05, 2010
Posts: 60
|
|
|
With the exception of methods from Anonimous classes of course. Tecnically are inside a methods
|
 |
Badal Chowdhary
Ranch Hand
Joined: Apr 26, 2011
Posts: 34
|
|
|
Abhinav, the question is what are you trying to achieve here?
|
Blog: http://badalchowdhary.wordpress.com/
Twitter: http://twitter.com/badalrocks
|
 |
abhinav sood
Greenhorn
Joined: Aug 05, 2011
Posts: 9
|
|
|
I wanted to know how the reference variable works if a method contain nested methods.......
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
Alex Armenteros wrote:With the exception of methods from Anonimous classes of course. Tecnically are inside a methods
You can define classes inside methods (not just anonymous classes). This is valid Java, for example:
But you cannot define methods directly inside methods.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Badal Chowdhary
Ranch Hand
Joined: Apr 26, 2011
Posts: 34
|
|
|
Basically, methods cannot be nested in methods. A method can only be inside a class.
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4095
|
|
praise the lord!
|
SCJP
|
 |
 |
|
|
subject: why not we define a static member function inside a main
|
|
|