How to reference non-static variable name from static context?

前端 未结 5 642
闹比i
闹比i 2021-01-21 02:22

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         


        
5条回答
  •  迷失自我
    2021-01-21 02:46

    Static methods/variables are bound to class. They have no access to non-static variables ( they have no idea on which instance of class they should call the method). You have to create object, and then call the non-static method.

提交回复
热议问题