2. The main method in a member variable, too? What is meaning?
3. In the call and structure, the incoming name, age value can only be null? How can the specific value?
CodePudding user response:
1, in terms of your code, the name is a member variable,2, is not a member variable, belongs to an instance of a class, is a local variable in the main,
3, is your member variable of the type of Student, if you have any constructor instantiates refs to use, can new two Student object, you want the new two Student class object, and only then the new four objects,,,, only an infinite loop, this is wrong, if you really want to this statement, can add a Student class a no-parameter constructor, but doing so in fact doesn't make sense, because of your member variables are two Student object, for the member variable assignment must have specific Student class instance,
Reason I didn't understand your code?????? Do you want to set up two attributes in the student class name and age?
You can
class Student
{
public String name;
Public int the age;
Public Student (String name, int age)
{
This. Name=name;
Enclosing the age=age;
}
}
And then it can be new instance,
Student s=new Student (" zhangsan ", 25);
System. The out. Println (s.n ame);//zhangsan
CodePudding user response:
If you want to declare singly linked lists, you can node such statement.public class ListNode {
String name;//node values
int age;//node values
ListNode next;//next pointer to the next node, which is another ListNode next=object, end node next=null
ListNode (String name, int age) {
This. Name=name;
Enclosing the age=age;
}
}
CodePudding user response:
Originally a is an instance of understand, thank you