• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array helps

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried created unititlazed array but the compiler said the field is never read locally, wrong:


public class Ve {
private En eng;//create instance variable
private Ti[] tire=new Ti[4];//create uninitialized array
private Do[] doo=new Do[2];

Ti and Do are two classes in the same class as Ve.
Thanks
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see three variables (eng, tire, doo) and none of them are read in this code (not surprising, it's only three lines long.) What's your question? Where do you think these are being read, but the compiler disagrees?
 
Rayt Leeop
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:I see three variables (eng, tire, doo) and none of them are read in this code (not surprising, it's only three lines long.) What's your question? Where do you think these are being read, but the compiler disagrees?



My question is that it is ok or not. Look it does not work. Did I do right to create uninitialized array of Doo? and Ti?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you created two empty ("uninitialized") arrays. The warning is telling you that although you defined them, you don't use the data contained in them anywhere else in your code. If this is all the code you have so far, then that's not surprising.
 
Rayt Leeop
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:Yes, you created two empty ("uninitialized") arrays. The warning is telling you that although you defined them, you don't use the data contained in them anywhere else in your code. If this is all the code you have so far, then that's not surprising.



Many thanks. The reason that i created it is to let subclass (another class) to initialize them. Can you tell me how to print like
Ti 1: 0
Ti 2: 0
?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not given us nearly enough information to answer your question. I could answer with


but I'm also pretty sure that is not what you want.

I am NOT sure what you DO want. Can you give us the details of what you are really trying to do?
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can you get a subclass to initialise superclass fields? That is really bad design.
 
reply
    Bookmark Topic Watch Topic
  • New Topic