I'm new to Java programming and I'm following a guide on Udemy. I'm working with data manipulation through classes, this one being a simple name formatter. Predefined strings (parts of a name) are inserted into the class to format them.
This program uses two classes: Name.java and NameTest.java (the driver file)
Name.java:
package javaProject;
public class Name {
private String first;
private String middle;
private String last;
public Name(String f, String m, String l){
first = f;
middle = m;
last = l;
}
public Name(String f, String l){
first = f;
middle = "";
last = l;
}
public Name(String f){
first = f;
middle = "";
last = "";
}
public Name(){
first = "";
middle = "";
last = "";
}
///
public String displayName(){
return first + " " + middle + " " + last;
}
public static void main(String[] args){
}
}
NameTest.java:
package javaProject;
public class NameTest{
public static void main(String[] args){
Name myName = new Name("Damon", "myMiddleName", "myLastName");
System.out.println("My Name: " + myName.toString());
}
}
Output:
My Name: javaProject.Name@35afe17b
Any idea why I'm getting this after specifying that the output should be a string? I'm not exactly sure how to fix this because, again, I'm really new to Java.