Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cryptic java declaration

 
vi ch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anyone explain the statement
Fruit lime, kumqat=new Fruit(), raspberry;
Thanks
Vidyu
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure,
Fruit lime, kumqat=new Fruit(), raspberry;
declares three reference variables of type Fruit, lime, kumqat and raspberry. Only kumqat gets initialized (new Fruit()). The statement is the same as the three following:
Fruit lime;
Fruit kumqat = new Fruit();
Fruit raspberry;
You can declare (and initialize) several references of the same type on the same line, just separate them by commas.
We would like you to read the Javaranch Naming Policy and register again.
Thank you for your cooperation
HIH
[ January 17, 2002: Message edited by: Valentin Crettaz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic