The first error message is pretty clear and logical.
As for the second one, you are trying to put System.out.println(); statement outside of method body which results in an error.
The quieter you are, the more you are able to hear.
Joined: Oct 18, 2012
In the following program:
Output is 0.
The article on this site states that In the absence of a user-defined constructor, Java defines a default constructor. This constructor doesn't accept any method arguments. It calls the constructor of the base class and assigns default values to all the instance variables. and assign them to null.
Is there any difference between Zero and null in Java because the output of the program is Zero ?
That article is more‑or‑less correct. But not quite correct. You should read the Java Language Specification (JLS) for the official version.
The JLS uses the official term, superclass, rather than base, and it tells you it has an empty body or a super(); call only.
It does not initialise any fields at all. The fields already contain their default values, and the default constructor simply leaves them unchanged. You will have to search the JLS for the details; I didn’t find them. This Java Tutorials page might help.
You are correct that nulls are only applied to reference types. For primitives the fields are initialised to 0, which is interpreted as false for booleans and the “null character” for chars.
Joined: Oct 13, 2005
Earlier, I wrote: . . . This Java Tutorials page might help. . . .