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{


Post a Reply


- page 2
Oldest  Newest  Rating
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 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


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

Bucky Roberts Administrator