Mihir
Mihir

Reputation: 95

No dataType in variable declaration

Java documentation says

Field declarations are composed of three components, in order:

  1. Zero or more modifiers, such as public or private.
  2. The field's type.
  3. The field's name.

however, variable declaration in this post has confused me.

private final firstName;
private final lastName;

I cannot understand why there is no dataType for first two variables declared?

Whereas, 3rd and 4th has?

private final Date birthdate;
private final Address address;

Note:Am learning Java, hence to understand if am missing on anything related to variable declaration.

Upvotes: 0

Views: 65

Answers (2)

xingbin
xingbin

Reputation: 28269

That post is incorrect, it should be:

private final String firstName;
private final String lastName;

Upvotes: 1

Nassir
Nassir

Reputation: 13

It because he made a mistake forgetting to place a data type on those variable. So it should look like this:

private final String firstName;
private final String lastName; 

Upvotes: 0

Related Questions