-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{ ... } 

Is it possible to call an object instance in a static method when the instance was created in the main method?

1
  • 1
    The whole point of static methods is that they are not tied to some instance and they are "Class level" methods. You can do it by passing this instance as a parameter for example Commented Oct 21, 2017 at 5:50

1 Answer 1

0

I don't know whether I understood your question correctly, If I got it wrong, please leave a comment.

add a parameter to your static function and pass your object to that function through the parameter.

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{ ... } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.