Results 1 to 7 of 7
  1. #1
    Splanger is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default the method creates a new object and initializes it...

    In Oracle's Java tutorial there is an example about parameters passing into the method:

    Here's an example of a method that accepts an array as an argument. In this example, the method creates a new Polygon object and initializes it from an array of Point objects (assume that Point is a class that represents an x, y coordinate):

    Java Code:
    public Polygon polygonFrom(Point[] corners) {
        // method body goes here
    }
    I just cannot understand what does it mean "to create a new object AND initialize it at the same time". Isn't it Constructor's and the new operator job?
    Can some body explain me please the example above with mpore details and sample how to use it?

    Very thank you!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    The method body could be:
    Polygon pg = new Polygon(corners); // create a new object AND initialize it
    return pg;

  3. #3
    Splanger is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Ok... but still, what does the declaration means?

    Java Code:
    public Polygon polygonFrom(Point[] corners)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Java Code:
    public Polygon polygonFrom(Point[] corners)
    That line defines a method named polygonFrom() that takes an array of Point as argument and returns a reference to a Polygon object.

  5. #5
    Splanger is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    returns a reference to a Polygon object.
    what is it "reference to an object"?
    is it value or what?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Time for you to do some research. These are basic concepts for Java programming.

    Var reference = new Var(); // reference refers to/points at an instance of the class Var.

  7. #7
    Splanger is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    thanks!

    probably at the continue of the tutorial it will be explained, but it's strange, that they're using terms and aren't explaining the at the same place.

Similar Threads

  1. who initializes static members?
    By munishvit in forum New To Java
    Replies: 10
    Last Post: 12-27-2010, 06:43 AM
  2. Replies: 0
    Last Post: 10-13-2010, 07:26 PM
  3. When the compiler creates the variable?
    By hitesh_public in forum New To Java
    Replies: 14
    Last Post: 08-17-2010, 11:21 AM
  4. Replies: 2
    Last Post: 01-29-2010, 03:01 AM
  5. How to run method from a different object?
    By anyone in forum New To Java
    Replies: 10
    Last Post: 01-16-2010, 10:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •