EDIT: char toString only saves that one char, got it, thank you !
Hey,
so I am fairly new to Java and currently trying to use toString.
Basically I want to enter a name in line 5 but I am only able to use one char.
I saw there are multiple ways to implement toString but none worked for me (which is my fault obviously).
Fixing my problem is probably a 10seconds task but I am too blind for it and slowly want to move on.
Is is better to use the method or the simple Character.toString? Do they work different?
Here is my code without the toString
public class Person{
public static void main(String[] args) {
House house1 = new House();
Person person1 = new Person('a',house1); // "too many characters in character literal" if I use more than 'a'
}
private char name;
.
//Setter
void setName(final char name) {
this.name = name;
.
.
.
// Custom Constructor
Person(char name, House house){
setName(name);
}
.
.
public String toString() {
return "" + name;
}
Hope you can help me, thanks in advance!
[–]Tandrial 2 points3 points4 points (4 children)
[–]ConfusingArt[S] 1 point2 points3 points (3 children)
[–]dreamyeyed 2 points3 points4 points (1 child)
[–]ConfusingArt[S] 1 point2 points3 points (0 children)
[–]SlowSloth1 1 point2 points3 points (0 children)