Home > Back-end >  Don't understand ask series
Don't understand ask series

Time:12-05

Just learn Java se array of objects, the end of the tutorial times array some don't understand, I have a big willing to answer a thing or two?
The thing is:
Tutorials created several objects, and then create an array of objects, and then to traverse the array of objects to investigate whether can use, normal array traversal is not print x [z] can traverse all elements of the array, but an array of objects can't use this kind of traverse, said to get an array of objects within the group leaders will create a obtain attribute, the method of the tutorial is to introduce a package, and in the package created a public show method, and then use x [z]. The show () to get all attributes of the array of objects, and if I put it in directly into the same package, as shown in the figure below?

CodePudding user response:

SRT is variable type in two, I think later may not be in this variable types, so plan to replace with other, as long as know the composition of it is made up of what, then, nk, CLR, nl is a variable name, X p is the name of the class

CodePudding user response:

refer to the original poster qq_49818874 response:
just learn Java se array of objects, the end of the tutorial times array I some don't understand, who willing to answer a thing or two?
The thing is:
Tutorials created several objects, and then create an array of objects, and then to traverse the array of objects to investigate whether can use, normal array traversal is not print x [z] can traverse all elements of the array, but an array of objects can't use this kind of traverse, said to get an array of objects within the group leaders will create a obtain attribute, the method of the tutorial is to introduce a package, and in the package created a public show method, and then use x [z]. The show () to get all attributes of the array of objects, and if I put it in directly into the same package, as shown in the figure below?


Your class has three variables show method shows the two variables, but can be by rewriting the toString method to achieve the same effect,

CodePudding user response:

refer to the second floor qq_39936465 response:
Quote: refer to the original poster qq_49818874 response:
just learn Java se array of objects, the end of the tutorial times array I some don't understand, who willing to answer a thing or two?
The thing is:
Tutorials created several objects, and then create an array of objects, and then to traverse the array of objects to investigate whether can use, normal array traversal is not print x [z] can traverse all elements of the array, but an array of objects can't use this kind of traverse, said to get an array of objects within the group leaders will create a obtain attribute, the method of the tutorial is to introduce a package, and in the package created a public show method, and then use x [z]. The show () to get all attributes of the array of objects, and if I put it in directly into the same package, as shown in the figure below?


Your class have three variables show method shows the two variables, but can be by rewriting the toString method to achieve the same effect,
toString method... That's what, show variable can be added, can give the three variables are no problem, how to traverse the problem really is behind don't understand

CodePudding user response:

To understand the toString method of the Object class, override the toString method is ok, don't have to write what show method

CodePudding user response:

Why the string class, the integer class can print directly, why can't you create a class print directly, because these are the toString method

CodePudding user response:

When printing automatically call the toString (), need to rewrite this method, to achieve the desired effect

CodePudding user response:

references a handsome, 4/f, forced response:
to understand the toString method of the Object class, override the toString method is ok, don't have to write what show method
but I have not learned there??

CodePudding user response:

reference qq_49818874 reply: 3/f
toString method... That's what, show variable can be added, can give the three variables are no problem, how to traverse the problem really is behind understand


ToString is the method of Object class and Object class is the parent class of all classes, finally a traversal traversal is an array of X class, it's not a complicated, you just when the normal data traversal, each element of the array is an instance of class X,

CodePudding user response:

Override the toString ()
  • Related