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
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. 
0 Developer John · February 10, 2015
Isn't it because an object's state is stored in stored in its fields, while an object's behavior is stored in its methods? There should be a connection to that. 
0 Mathias Frits Rørvik · February 10, 2015
Never mind, I am mistaken. I was unaware that you actually can define a class within a method, but you can't call methods outside methods. I guess in short you could say that a class can only contain definitions. 
0 Developer John · February 10, 2015
Yes.
  • 1
  • 2

Java / Android Development

106,943 followers
About

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

Links
Moderators
Bucky Roberts Administrator