Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java How do I create an instance of a class in a method using Java?

  1. Mar 11, 2015 #1
    1. The problem statement, all variables and given/known data

    How do I create an instance of a class in a method?

    2. Relevant equations


    3. The attempt at a solution

    I am a bit rusty whenever I think of instances. I always think of main method and objects when I see instance which gets me confused on what to do with the following example:

    I have a abstract class, School, and inside School I have some methods that must preform some action on an instance. For example, there is a move() method that must move the instance of School. Another method named, personOld(), which returns whether or not an instance of School surpassed some determined age.
    How do I create this instance?
    Last edited: Mar 11, 2015
  2. jcsd
  3. Mar 11, 2015 #2
  4. Mar 11, 2015 #3
    Hm, in those examples they put the objects in the main method which is what I always think of when I see instance, but I have a class which isn't a main method which is what has gotten me confused.

    Since my constructor, in my abstract School class, has many parameters then I must Constructor.newInstance()?

    But how do I apply this?
  5. Mar 12, 2015 #4

    Filip Larsen

    User Avatar
    Gold Member

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook