char[] name = "VIKKYHACKS".toCharArray();
System.out.println(name.length);
In this program what is the "length" , If it were (new String("VIKKYHACKS")).length()
then the length would be a method. But char[] is a datatype and cannot have fields or methods inside it. How does the second line of that program work ???
char[] is not a primitive data type. it is an Object, and it has a public field 'length'.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
That is a good start.
Because Arrays are Objects, they have all the other items, like an equals() and hashCode() method too. (as well as all the treats like notify(), wait(), etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With