Lorenzo
Lorenzo

Reputation: 197

Signature of method with 'new Class()' as parameter

I saw a line of code where I don't know what the signature of that method looks like. I've searched online for some examples and an explanation, but didn't find one.

The line of code:

Circle sum = Circle.add(new Circle(), new Circle());

I was wondering how the signature of the add method would look like with the 'new Circle()' as parameter.

Upvotes: 0

Views: 63

Answers (3)

Shmulik Klein
Shmulik Klein

Reputation: 3914

Without knowing this API, you can use the following hints:

  • This method receives two parameters (or more...) of types Circle and returns an object of type Circle.
  • The method is accessed through the Circle.add(...), so it must be a static method

So the signature for this method will look something like:

public static Circle add(Circle c1, Circle c2);

or

public static Circle add(Circle... circles);

(the access modifier of the method can be other than public)

Upvotes: 4

Youcef LAIDANI
Youcef LAIDANI

Reputation: 59986

Because it take same Object Circle Object, i also suggest it can take an array of Circle and return a Circle Object in the end like this :

public class Circle{

    public Circle() {
    }

    public static Circle add(Circle...circles){
        Circle c = ...;
        //do soemthing
        return c;
    }
}

Or simply your class conscructor can take two Circle like this :

public class Circle{

    public static Circle add(Circle c1, Circle c2){
        Circle c = ...;
        //do soemthing
        return c;
    }
}

Upvotes: 1

Jiri Tousek
Jiri Tousek

Reputation: 12440

Signature is possibly:

add(Circle, Circle)

new Circle() is no-params constructor call.

Upvotes: 1

Related Questions