Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7758689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:25:37+00:00 2026-06-01T13:25:37+00:00

I am trying to understand the difference between 2 methods that have the same

  • 0

I am trying to understand the difference between 2 methods that have the same name. This is the code I am trying to understand…

public class Test {
    public static void main(String[] args) {
        MyPoint p1 = new MyPoint();
        MyPoint p2 = new MyPoint(10, 30.5);
        System.out.println(p1.distance(p2));
        System.out.println(MyPoint.distance(p1, p2));
    }
}

class MyPoint {
    .....   
}

public double distance(MyPoint secondPoint) {
    return distance(this, secondPoint);
}

public static double distance(MyPoint p1, MyPoint p2) {
    return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}

Could someone please explain the difference between the 2 distance() methods. What does the type MyPoint actually mean? Why does 1 of the methods have a single MyPoint object, whereas the other method has 2 MyPoint objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:25:38+00:00Added an answer on June 1, 2026 at 1:25 pm

    MyPoint is the type of the object. In the distance(MyPoint p1, MyPoint p2) method, for example, it means that you are passing in 2 objects to this method – the first object is a MyPoint object called p1, and the second object is another MyPoint object called p2.

    The difference between the 2 println statements is that the first one runs the distance(MyPoint) method, and the second one runs the distance(MyPoint, MyPoint) method. Additionally, the first method runs the distance() from the MyPoint p1 object to the one passed in to the method (p2), whereas the second distance() method is a static call which calculates the distance between the 2 MyPoint objects passed in to the method (p1 and p2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand the difference between this: if (isset($_POST['Submit'])) { //do something
I am trying to understand the difference between this list: UIRequiredDeviceCapabilities and individual keys
Been trying my best to understand this correctly. What is the difference between an
I am trying to understand this particular difference between the direct and delegated event
I have been trying to understand the difference between different references but the theory
I am trying to understand the difference between these four methods. I know by
I have been reading many articles trying to understand the difference between functional and
I am trying to understand the difference between mysqli's query() and prepare(). I have
I'm trying to understand the difference between a squash and a rebase. As I
I'm trying to understand the difference between sequences and lists. In F# there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.