Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Is length an instance variable?

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At first consider the following program snippet......

length of line 1 seems to be an instance variable. If so, which class' object does it belong to?
And what I think is somewhere( in any class ) it is declared like....

May I have your opinion please.............................
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every array object belongs to a class which is type of created dynamically for every component type. For ex., one class for int[], one for String[] etc and all array object of a type share same class.

These array classes have member variable "public final length", which gives the number of elements in the array.

Read JLS section for more info.
 
Arijit Daripa
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Santhosh Kumar:

These array classes have member variable "public final length", which gives the number of elements in the array.



public final ??? length
That must be public final int length


And thanks for your opinion Mr. Santosh.
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic