Java Nested Class Question

0 Developer John · February 9, 2015
Why isn't this valid when making a Java nested class:


public class Hello{

public static void main(String[] args){

class Test{
System.out.println();
}
}
}

-Thanks!8-)

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 Developer John · February 9, 2015
Oh yes, my question wasn't on how method references work when compiled.
0 Nicholas Eason · February 9, 2015
You said: "Oh wow, I can't believe I forgot to create a method. What kind of statements are acceptable inside the class body, but outside a constructor or method body?"
And: "Okay, so a class body can only contain fields that are variable declarations, but why?"


Your questions definitely resembled that question, along with an example of a print statement not inside a method. I simply gave a visual example along with the worded explanation because I don't know how you learn, so to attempt to get my point across in one post, I try to include visual examples.
0 Mathias Frits Rørvik · February 9, 2015
You can't declare classes within a method.
0 Developer John · February 9, 2015
Mathias, who are you in reference to? Please explain your comment. Secondly, I wanted to know if there were certain statements that could be declared within a class body. A variable declaration is a statement, but I wanted to know if there was any other valid statement. 
  • 1
  • 2

Java / Android Development

107,052 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator