2017-10-21 269 views
-1
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{ 
... 
} 

当在主方法中创建实例时,是否可以在静态方法中调用对象实例?对象 - 在静态方法内调用对象实例

+1

静态方法的要点是它们不受某些实例束缚,它们是“类级别”方法。例如,可以通过将此实例作为参数传递来完成此操作 – sborpo

回答

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{ 
... 
} 
相关问题