I am trying to write a code that lets the user enter a team name. Here is my code:
public class Team {
public String name;
public static void main(Strin
static
methods do not allow to use the non-static variables directly because non-static/instance
variables are initialized in memory on object creation. Hence you need to create an object of the the class and then use the variable. Do something like this:
Team teamObj = new Team();
//now access name variable using teabObj instance
teamObj.name = tn.nextLine();