I'm trying to make a table list with names that I provide as input. But instead of just displaying the table with "object.getName();", I inserted a method from another class that is retrieving data from "another" class and displays them in a table. But the values are still null.
public class Sample {
public static void main(String[] args) {
addclass add = new addclass();
table tab = new table();
add.addclass();
tab.table();
}
}
public class table {
addclass add = new addclass();
public void table(){
System.out.print("Name: " + add.getName());
}
}
public class addclass {
private String name;
Scanner input = new Scanner(System.in);
public void addclass(){
System.out.print("Name: ");
setName(input.nextLine());
}
public void setName(String newName){
this.name = newName;
}
public String getName(){
return name;
}
}