1

what would be the name of class representing an array object? eg:

int a[] = new int[5]

here a is the reference variable. what is the name of class whoes object's reference id hold in a System.out.println(a.getClass().getName()) prints [I

is there any rule for naming?

0

2 Answers 2

5

Class name for Array in java

For Java arrays,the class name is '[' followed by an encoded name of the element class. The number of '[' character represent the number of dimension of the array

Element Type   Encoding

byte              B

boolean           Z

char              C

double            D

float             F

int               I

long              J

short             S

class or interface   Lclassname; 

for example : for float type array class name is [F

for int [I

for double a[][]=new double[2][3]

class name is [[D

source: http://ohmjavaclasses.blogspot.com/2011/12/class-name-for-array-in-java.html

Sign up to request clarification or add additional context in comments.

Comments

1

In general, your class should have a name taken from the problem domain model's vocabulary.

Example: If you need to keep an array of books Book[] books then a good bet would be to create a Library class holding a reference to those books.

To comeback to your question, it depends on what a will contain.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.