public class create{
public static void main(String[] args){
Student myStudent = new Student();
...
}
public static String makeStudent()
{
student.set(x);
student.get(x);
}}
public Student{
...
}
当在main方法中创建实例时,是否可以在静态方法中调用对象实例?
答案 0 :(得分:0)
我不知道我是否理解你的问题,如果我弄错了,请发表评论。
向静态函数添加一个参数,并通过参数将对象传递给该函数。
public class create{
public static void main(String[] args){
Student myStudent = new Student();
makeStudent(myStudent);
}
public static String makeStudent(Student student)
{
student.set(x);
student.get(x);
}}
public Student{
...
}