wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Just an experiment (cause'  I'm new to Java). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Just an experiment (cause Watch "Just an experiment (cause New topic
Author

Just an experiment (cause' I'm new to Java).

Rasul Patrick
Greenhorn

Joined: Oct 18, 2012
Posts: 20


Please illustrate.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
Rasul Patrick
Greenhorn

Joined: Oct 18, 2012
Posts: 20
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 ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
Earlier, I wrote: . . . This Java Tutorials page might help. . . .
And then again, it might not help.
 
Consider Paul's rocket mass heater.
 
subject: Just an experiment (cause' I'm new to Java).
 
Similar Threads
Regarding Package
5 Golden Rules of widening, boxing & varargs
Error: Cannot find symbol during Importing package
in the below code what could be the statement to display the output of a+b.
Assertion ?