• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Please illustrate.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rasul Patrick
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Marshal
Posts: 76861
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 76861
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Earlier, I wrote: . . . This Java Tutorials page might help. . . .

And then again, it might not help.
 
Let nothing stop you! Not even this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic